From 685235795cbbb7e528407975db8b6913913ce65a Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 6 Apr 2006 19:51:37 +0000 Subject: [PATCH] Apple 2 mouse driver and other stuff from Oliver Schmidt git-svn-id: svn://svn.cc65.org/cc65/trunk@3717 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/apple2.sgml | 29 ++- doc/apple2enh.sgml | 26 ++- doc/library.sgml | 3 + libsrc/Makefile | 6 +- libsrc/apple2/.cvsignore | 1 + libsrc/apple2/Makefile | 15 +- libsrc/apple2/apple2-stdmou.s | 411 ++++++++++++++++++++++++++++++++++ libsrc/apple2/cputc.s | 2 +- libsrc/apple2/dosdetect.s | 2 +- libsrc/apple2/mainargs.s | 2 +- libsrc/apple2/mcbdefault.s | 136 +++++++++++ libsrc/apple2enh/.cvsignore | 1 + libsrc/apple2enh/Makefile | 14 +- libsrc/mouse/mouse-kernel.s | 23 +- samples/Makefile | 14 +- samples/README | 2 +- samples/mousedemo.c | 19 +- 17 files changed, 660 insertions(+), 46 deletions(-) create mode 100644 libsrc/apple2/apple2-stdmou.s create mode 100644 libsrc/apple2/mcbdefault.s diff --git a/doc/apple2.sgml b/doc/apple2.sgml index dc48a8939..e933d49fb 100644 --- a/doc/apple2.sgml +++ b/doc/apple2.sgml @@ -130,9 +130,9 @@ you cannot do it, it just means that there's no help. Gives access to 12KB RAM (48 pages of 256 bytes each) on the - Apple2 language card. The driver was contributed by Stefan Haubenthal. - Note that this driver is incompatible with any DOS using the language - card memory! + Apple II Language Card. The driver was contributed by Stefan Haubenthal. + Note that this driver is incompatible with any DOS using the Language + Card memory!

@@ -150,8 +150,20 @@ you cannot do it, it just means that there's no help. Mouse drivers

-Currently no drivers available (in fact, the API for loadable mouse drivers -does not exist). + + + + Driver for the AppleMouse II Card. Searches all Apple II slots + for an AppleMouse II Card compatible firmware. The default bounding + box is [0..279,0..191]. Programs using this driver will have + to be linked with

RS232 device drivers

@@ -159,11 +171,16 @@ does not exist). - Driver for the Apple2 Super Serial Card. Supports up to 19200 baud, + Driver for the Apple II Super Serial Card. Supports up to 19200 baud, hardware flow control (RTS/CTS) and interrupt driven receives. Note that because of the peculiarities of the 6551 chip transmits are not interrupt driven, and the transceiver blocks if the receiver asserts flow control because of a full buffer. + + The driver defaults to slot 2. Call ser_ioctl(0, ) prior to ser_open + in order to select a different slot. ser_ioctl succeeds for all Apple II + slots, but ser_open fails with SER_ERR_NO_DEVICE if there's no SSC firmware + found in the selected slot.

diff --git a/doc/apple2enh.sgml b/doc/apple2enh.sgml index 5b3301da7..8d4bb4e96 100644 --- a/doc/apple2enh.sgml +++ b/doc/apple2enh.sgml @@ -132,9 +132,9 @@ you cannot do it, it just means that there's no help. Gives access to 12KB RAM (48 pages of 256 bytes each) on the - Apple2 language card. The driver was contributed by Stefan Haubenthal. - Note that this driver is incompatible with any DOS using the language - card memory! + Apple II Language Card. The driver was contributed by Stefan Haubenthal. + Note that this driver is incompatible with any DOS using the Language + Card memory!

@@ -152,8 +152,17 @@ you cannot do it, it just means that there's no help. Mouse drivers

-Currently no drivers available (in fact, the API for loadable mouse drivers -does not exist). + + + + Driver for the AppleMouse II Card. Searches all Apple II slots + for an AppleMouse II Card compatible firmware. The default bounding + box is [0..279,0..191]. + + Note that the enhanced Apple //e default mouse callbacks support + text mode only. + +

RS232 device drivers

@@ -161,12 +170,17 @@ does not exist). - Driver for the Apple2 Super Serial Card. Supports up to 19200 baud, + Driver for the Apple II Super Serial Card. Supports up to 19200 baud, hardware flow control (RTS/CTS) and interrupt driven receives. Note that because of the peculiarities of the 6551 chip transmits are not interrupt driven, and the transceiver blocks if the receiver asserts flow control because of a full buffer. + The driver defaults to slot 2. Call ser_ioctl(0, ) prior to ser_open + in order to select a different slot. ser_ioctl succeeds for all Apple II + slots, but ser_open fails with SER_ERR_NO_DEVICE if there's no SSC firmware + found in the selected slot. +

diff --git a/doc/library.sgml b/doc/library.sgml index 1cae5159b..2860b3a5d 100644 --- a/doc/library.sgml +++ b/doc/library.sgml @@ -164,6 +164,7 @@ portable. conio implementations exist for the following targets: apple2 + apple2enh atari c16 (works also for the c116 with up to 32K memory) c64 @@ -195,6 +196,8 @@ Some target machines support a mouse. Mouse support is currently available for the following targets: + apple2 + apple2enh atari c64 c128 diff --git a/libsrc/Makefile b/libsrc/Makefile index 5537591ef..81bcb04cf 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -42,13 +42,14 @@ all: # Apple ][ apple2lib: - for i in apple2 common runtime conio dbg em joystick serial tgi zlib; do \ + for i in apple2 common runtime conio dbg em joystick mouse serial tgi zlib; do \ $(MAKE) SYS=apple2 -C $$i || exit 1; \ $(AR) a apple2.lib $$i/*.o;\ done mv apple2/crt0.o apple2.o cp apple2/apple2-lc.emd a2.lc.emd cp apple2/apple2-stdjoy.joy a2.stdjoy.joy + cp apple2/apple2-stdmou.mou a2.stdmou.mou cp apple2/apple2-ssc.ser a2.ssc.ser cp apple2/apple2-40-40-16.tgi a2.lo.tgi cp apple2/apple2-280-192-6.tgi a2.hi.tgi @@ -57,13 +58,14 @@ apple2lib: # Apple //e apple2enhlib: - for i in apple2enh common runtime conio dbg em joystick serial tgi zlib; do \ + for i in apple2enh common runtime conio dbg em joystick mouse serial tgi zlib; do \ $(MAKE) SYS=apple2enh -C $$i || exit 1; \ $(AR) a apple2enh.lib $$i/*.o;\ done mv apple2enh/crt0.o apple2enh.o cp apple2enh/apple2-lc.emd a2e.lc.emd cp apple2enh/apple2-stdjoy.joy a2e.stdjoy.joy + cp apple2enh/apple2-stdmou.mou a2e.stdmou.mou cp apple2enh/apple2-ssc.ser a2e.ssc.ser cp apple2enh/apple2-40-40-16.tgi a2e.lo.tgi cp apple2enh/apple2-280-192-6.tgi a2e.hi.tgi diff --git a/libsrc/apple2/.cvsignore b/libsrc/apple2/.cvsignore index 254bf4a68..3cb6ab2ff 100644 --- a/libsrc/apple2/.cvsignore +++ b/libsrc/apple2/.cvsignore @@ -1,5 +1,6 @@ *.emd *.joy +*.mou *.ser *.tgi closedir.s diff --git a/libsrc/apple2/Makefile b/libsrc/apple2/Makefile index b8b55119d..953bf510d 100644 --- a/libsrc/apple2/Makefile +++ b/libsrc/apple2/Makefile @@ -32,6 +32,9 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include %.joy: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ +%.mou: %.o ../runtime/zeropage.o + @$(LD) -t module -o $@ $^ + %.ser: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ @@ -76,6 +79,7 @@ S_OBJS= _scrsize.o \ joy_stddrv.o \ kbhit.o \ mainargs.o \ + mcbdefault.o \ mli.o \ open.o \ oserrlist.o \ @@ -109,6 +113,8 @@ EMDS = apple2-lc.emd JOYS = apple2-stdjoy.joy +MOUS = apple2-stdmou.mou + SERS = apple2-ssc.ser TGIS = apple2-40-40-16.tgi apple2-280-192-6.tgi @@ -118,14 +124,13 @@ TGIS = apple2-40-40-16.tgi apple2-280-192-6.tgi .PHONY: all clean zap -all: $(C_OBJS) $(S_OBJS) $(EMDS) $(JOYS) $(SERS) $(TGIS) +all: $(C_OBJS) $(S_OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS) ../runtime/zeropage.o: $(MAKE) -C $(dir $@) $(notdir $@) clean: - @$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) - -zap: clean - @$(RM) $(EMDS) $(JOYS) $(SERS) $(TGIS) + @$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(MOUS:.mou=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) +zap: clean + @$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS) diff --git a/libsrc/apple2/apple2-stdmou.s b/libsrc/apple2/apple2-stdmou.s new file mode 100644 index 000000000..f8a04c9e1 --- /dev/null +++ b/libsrc/apple2/apple2-stdmou.s @@ -0,0 +1,411 @@ +; +; Driver for the AppleMouse II Card. +; +; Oliver Schmidt, 03.09.2005 +; + + .include "zeropage.inc" + .include "mouse-kernel.inc" + +; ------------------------------------------------------------------------ + +SETMOUSE = $12 ; Sets mouse mode +SERVEMOUSE = $13 ; Services mouse interrupt +READMOUSE = $14 ; Reads mouse position +CLEARMOUSE = $15 ; Clears mouse position to 0 (for delta mode) +POSMOUSE = $16 ; Sets mouse position to a user-defined pos +CLAMPMOUSE = $17 ; Sets mouse bounds in a window +HOMEMOUSE = $18 ; Sets mouse to upper-left corner of clamp win +INITMOUSE = $19 ; Resets mouse clamps to default values and + ; sets mouse position to 0,0 + +pos1_lo := $0478 +pos1_hi := $0578 +pos2_lo := $04F8 +pos2_hi := $05F8 +status := $0778 + +; ------------------------------------------------------------------------ + + .segment "JUMPTABLE" + + ; Driver signature + .byte $6D, $6F, $75 ; "mou" + .byte MOUSE_API_VERSION ; Mouse driver API version number + + ; Jump table. + .addr INSTALL + .addr UNINSTALL + .addr HIDE + .addr SHOW + .addr BOX + .addr MOVE + .addr BUTTONS + .addr POS + .addr INFO + .addr IOCTL + .addr IRQ + + ; Callback table, set by the kernel before INSTALL is called +CHIDE: jmp $0000 ; Hide the cursor +CSHOW: jmp $0000 ; Show the cursor +CMOVEX: jmp $0000 ; Move the cursor to X coord +CMOVEY: jmp $0000 ; Move the cursor to Y coord + +; ------------------------------------------------------------------------ + + .bss + +slot: .res 1 +visible:.res 1 + +; ------------------------------------------------------------------------ + + .rodata + +offsets:.byte $05 ; Pascal 1.0 ID byte + .byte $07 ; Pascal 1.0 ID byte + .byte $0B ; Pascal 1.1 generic signature byte + .byte $0C ; Device signature byte + +values: .byte $38 ; Fixed + .byte $18 ; Fixed + .byte $01 ; Fixed + .byte $20 ; X-Y pointing device type 0 + +size = * - values + +; ------------------------------------------------------------------------ + + .data + +info: .word 279 / 2 ; MOUSE_INFO::MOUSE_POS::XCOORD + .word 191 / 2 ; MOUSE_INFO::MOUSE_POS::YCOORD + .byte %00000000 ; MOUSE_INFO::BUTTONS + +firmware: + ; Lookup and patch firmware address lobyte +lookup: ldy $FF00,x ; Patched at runtime + sty jump+1 ; Modify code below + + ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse: + ; "Enter all mouse routines (...) with the X register set to $Cn + ; and Y register set to $n0, where n = the slot number." +xparam: ldx #$FF ; Patched at runtime +yparam: ldy #$FF ; Patched at runtime + +jump: jmp $FFFF ; Patched at runtime + +; ------------------------------------------------------------------------ + + .code + +; INSTALL: Is called after the driver is loaded into memory. If possible, +; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X. +INSTALL: + lda #<$C000 + sta ptr1 + lda #>$C000 + sta ptr1+1 + + ; Search for AppleMouse II firmware in slots 1 - 7 +next: inc ptr1+1 + lda ptr1+1 + cmp #>$C800 + bcc :+ + + ; Mouse firmware not found + lda #MOUSE_ERR_NO_DEVICE + rts + + ; Check Pascal 1.1 Firmware Protocol ID bytes +: ldx #size - 1 +: ldy offsets,x + lda values,x + cmp (ptr1),y + bne next + dex + bpl :- + + ; Get and patch firmware address hibyte + lda ptr1+1 + sta lookup+2 + sta xparam+1 + sta jump+2 + + ; Convert to and save slot number + and #$0F + sta slot + + ; Convert to and patch I/O register index + asl + asl + asl + asl + sta yparam+1 + + ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse: + ; "Disable interrupts when calling any mouse routine." + sei + + ; Reset mouse hardware + ldx #INITMOUSE + jsr firmware + + ; Turn mouse on + lda #%00000001 + ldx #SETMOUSE + jsr firmware + + ; Set initial mouse clamps + lda #<279 + ldx #>279 + sta pos2_lo + stx pos2_hi + lda #$00 ; Set x clamps + sta pos1_lo + sta pos1_hi + ldx #CLAMPMOUSE + jsr firmware + lda #<191 + ldx #>191 + sta pos2_lo + stx pos2_hi + lda #$01 ; Set y clamps + ldx #CLAMPMOUSE + jsr firmware + + ; Set initial mouse position + ldx slot + lda #<(279 / 2) + sta pos1_lo,x + lda #>(279 / 2) + sta pos1_hi,x + lda #<(191 / 2) + sta pos2_lo,x + lda #>(191 / 2) + sta pos2_hi,x + ldx #POSMOUSE + jsr firmware + + ; Turn VBL interrupt on + lda #%00001001 + ldx #SETMOUSE +common: jsr firmware + + ; Enable interrupts and return success + cli + lda #MOUSE_ERR_OK + rts + +; UNINSTALL: Is called before the driver is removed from memory. +; No return code required (the driver is removed from memory on return). +UNINSTALL: + ; Hide cursor + sei + jsr CHIDE + + ; Turn mouse off + lda #%00000000 + ldx #SETMOUSE + bne common ; Branch always + +; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a +; counter for calls to show/hide, and the driver entry point is only called +; if the mouse is currently visible and should get hidden. For most drivers, +; no special action is required besides hiding the mouse cursor. +; No return code required. +HIDE: + dec visible + sei + jsr CHIDE + cli + rts + +; SHOW: Is called to show the mouse cursor. The mouse kernel manages a +; counter for calls to show/hide, and the driver entry point is only called +; if the mouse is currently hidden and should become visible. For most drivers, +; no special action is required besides enabling the mouse cursor. +; No return code required. +SHOW: + inc visible + rts + +; BOX: Set the mouse bounding box. The parameters are passed as they come from +; the C program, that is, maxy in A/X and the other parameters on the stack. +; The C wrapper will remove the parameters from the stack when the driver +; routine returns. +; No checks are done if the mouse is currently inside the box, this is the job +; of the caller. It is not necessary to validate the parameters, trust the +; caller and save some code here. No return code required. +BOX: + ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse: + ; "Disable interrupts before placing position information in the screen holes." + sei + + ; Set high clamp + sta pos2_lo + txa + + ldx #$01 ; Set y clamps + ldy #$00 ; Start at top of stack + jsr :+ + + ldx #$00 ; Set x clamps + ldy #$00 ; Start at top of stack + + ; Set high clamp + lda (sp),y + iny + sei + sta pos2_lo + lda (sp),y + iny +: sta pos2_hi + + ; Skip one parameter + iny + iny + + ; Set low clamp + lda (sp),y + iny + sta pos1_lo + lda (sp),y + sta pos1_hi + + txa + ldx #CLAMPMOUSE + bne common ; Branch always + +; MOVE: Move the mouse to a new position. The position is passed as it comes +; from the C program, that is: x on the stack and y in A/X. The C wrapper will +; remove the parameter from the stack on return. +; No checks are done if the new position is valid (within the bounding box or +; the screen). No return code required. +MOVE: + ldy slot + sei + + ; Set y + sta pos2_lo,y + txa + sta pos2_hi,y + + tya + tax + ldy #$00 ; Start at top of stack + + ; Set x + lda (sp),y + iny + sta pos1_lo,x + lda (sp),y + sta pos1_hi,x + + ; Update cursor + jsr update + + ldx #POSMOUSE + bne common ; Branch always + +; BUTTONS: Return the button mask in A/X. +BUTTONS: + lda info + MOUSE_INFO::BUTTONS + ldx #$00 + rts + +; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. +; No return code required. +POS: + ldx #.sizeof(MOUSE_POS)-1 + bne copy ; Branch always + +; INFO: Returns mouse position and current button mask in the MOUSE_INFO +; struct pointed to by ptr1. No return code required. +INFO: + ldx #.sizeof(MOUSE_INFO)-1 +copy: txa + tay + sei +: lda info,x + sta (ptr1),y + dex + dey + bpl :- + cli + rts + +; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl +; specific data in ptr1, and the ioctl code in A. +; Must return an MOUSE_ERR_xx code in A/X. +IOCTL: + lda #MOUSE_ERR_INV_IOCTL + rts + +; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All +; registers are already saved, no parameters are passed, but the carry flag +; is clear on entry. The routine must return with carry set if the interrupt +; was handled, otherwise with carry clear. +IRQ: + ; Check for mouse interrupt + ldx #SERVEMOUSE + jsr firmware + bcc :+ + clc ; Interrupt not handled + rts + +: ldx #READMOUSE + jsr firmware + + ; Get status + ldy slot + lda status,y + tax ; Save status + + ; Extract button down values + asl ; C = Button 0 is currently down + and #%00100000 ; !Z = Button 1 is currently down + + ; Set button mask + beq :+ + lda #MOUSE_BTN_RIGHT +: bcc :+ + ora #MOUSE_BTN_LEFT +: sta info + MOUSE_INFO::BUTTONS + + ; Check for mouse movement + txa ; Restore status + and #%00100000 ; X or Y changed since last READMOUSE + beq :+ + + ; Remove the cursor at the old position +update: jsr CHIDE + + ; Get and set the new X position + ldy slot + lda pos1_lo,y + ldx pos1_hi,y + sta info + MOUSE_POS::XCOORD + stx info + MOUSE_POS::XCOORD+1 + jsr CMOVEX + + ; Get and set the new Y position + ldy slot + lda pos2_lo,y + ldx pos2_hi,y + sta info + MOUSE_POS::YCOORD + stx info + MOUSE_POS::YCOORD+1 + jsr CMOVEY + + ; Check for visibility +: lda visible + beq :+ + + ; Draw the cursor at the new position + jsr CSHOW +: sec ; Interrupt handled + rts diff --git a/libsrc/apple2/cputc.s b/libsrc/apple2/cputc.s index 1b9373e5f..f3adc2f54 100644 --- a/libsrc/apple2/cputc.s +++ b/libsrc/apple2/cputc.s @@ -6,7 +6,7 @@ ; .ifdef __APPLE2ENH__ - .constructor initconio + .constructor initconio, 17 .endif .export _cputcxy, _cputc .export cputdirect, newline, putchar diff --git a/libsrc/apple2/dosdetect.s b/libsrc/apple2/dosdetect.s index 4fb6fcad6..0873bbcd8 100644 --- a/libsrc/apple2/dosdetect.s +++ b/libsrc/apple2/dosdetect.s @@ -20,7 +20,7 @@ ; ProDOS 8 2.0.3 - $23 ; - .constructor initdostype, 25 + .constructor initdostype, 19 .export __dos_type .include "mli.inc" diff --git a/libsrc/apple2/mainargs.s b/libsrc/apple2/mainargs.s index bf4511c00..a4736da9d 100644 --- a/libsrc/apple2/mainargs.s +++ b/libsrc/apple2/mainargs.s @@ -22,7 +22,7 @@ ; TO-DO: ; Add a control-character quoting mechanism. - .constructor initmainargs, 24 + .constructor initmainargs, 18 .import __argc, __argv, __dos_type .include "zeropage.inc" diff --git a/libsrc/apple2/mcbdefault.s b/libsrc/apple2/mcbdefault.s new file mode 100644 index 000000000..f270f9d70 --- /dev/null +++ b/libsrc/apple2/mcbdefault.s @@ -0,0 +1,136 @@ +; +; Default mouse callbacks for the Apple II +; +; Oliver Schmidt, 22.09.2005 +; +; All functions in this module should be interrupt safe, because they may +; be called from an interrupt handler +; + + .ifdef __APPLE2ENH__ + .constructor initmcb + .endif + .export _mouse_def_callbacks + + .include "apple2.inc" + +; ------------------------------------------------------------------------ + + .bss + +backup: .res 1 + +; ------------------------------------------------------------------------ + + .rodata + + ; Callback structure +_mouse_def_callbacks: + .addr hide + .addr show + .addr movex + .addr movey + +; ------------------------------------------------------------------------ + + .segment "INIT" + + .ifdef __APPLE2ENH__ +initmcb: + lda ALTCHARSET ; Alternate charset switched in? + bpl :+ ; No, normal charset + lda #'B' ; MouseText character + sta cmpcur+1 + sta getcur+1 +: rts + .endif + +; ------------------------------------------------------------------------ + + .data + +getcursor: + .ifdef __APPLE2ENH__ + bit RD80VID ; In 80 column mode? + bpl column ; No, skip bank switching +switch: bit LOWSCR ; Patched at runtime + .endif +column: ldx #$00 ; Patched at runtime +getscr: lda $0400,x ; Patched at runtime +cmpcur: cmp #'+' | $40 ; Possibly patched by initialization + rts + +setcursor: +getcur: lda #'+' | $40 ; Possibly patched by initialization +setscr: sta $0400,x ; Patched at runtime + .ifdef __APPLE2ENH__ + bit LOWSCR ; Doesn't hurt in 40 column mode + .endif + rts + +; ------------------------------------------------------------------------ + + .code + +done: + .ifdef __APPLE2ENH__ + bit LOWSCR ; Doesn't hurt in 40 column mode + .endif + rts + +; Hide the mouse cursor. +hide: + jsr getcursor ; Cursor visible at current position? + bne done ; No, we're done + lda backup ; Get character at cursor position + jmp setscr ; Draw character + +; Show the mouse cursor. +show: + jsr getcursor ; Cursor visible at current position? + beq done ; Yes, we're done + sta backup ; Save character at cursor position + jmp setcursor ; Draw cursor + +; Move the mouse cursor x position to the value in A/X. +movex: + dex ; Is position [256..279]? + bmi :+ ; No, start with column 0 + clc + adc #$0100 .MOD 7 ; Bias position + ldx #$0100 / 7 - 1 ; Bias column +: sec +: sbc #7 ; 280 positions / 40 columns + inx + bcs :- + stx column+1 + .ifdef __APPLE2ENH__ + adc #7 / 2 ; Left or right half of 40-col column? + ldx #$0400 ; 000001CD + sta getscr+2 + sta setscr+2 + txa ; ABCDExxx + ror ; EABCDExx + and #%11100000 ; EAB00000 + ora getscr+1 ; EABABCDE + and #%11111000 ; EABAB000 + sta getscr+1 + sta setscr+1 + rts diff --git a/libsrc/apple2enh/.cvsignore b/libsrc/apple2enh/.cvsignore index 581e5ff62..3eecd7b49 100644 --- a/libsrc/apple2enh/.cvsignore +++ b/libsrc/apple2enh/.cvsignore @@ -1,4 +1,5 @@ *.emd *.joy +*.mou *.ser *.tgi diff --git a/libsrc/apple2enh/Makefile b/libsrc/apple2enh/Makefile index 37384459d..a2a15278c 100644 --- a/libsrc/apple2enh/Makefile +++ b/libsrc/apple2enh/Makefile @@ -32,6 +32,9 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I ../apple2 -I ../../include %.joy: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ +%.mou: %.o ../runtime/zeropage.o + @$(LD) -t module -o $@ $^ + %.ser: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ @@ -76,6 +79,7 @@ S_OBJS= _scrsize.o \ joy_stddrv.o \ kbhit.o \ mainargs.o \ + mcbdefault.o \ mli.o \ open.o \ oserrlist.o \ @@ -110,6 +114,8 @@ EMDS = apple2-lc.emd JOYS = apple2-stdjoy.joy +MOUS = apple2-stdmou.mou + SERS = apple2-ssc.ser TGIS = apple2-40-40-16.tgi apple2-280-192-6.tgi @@ -119,15 +125,13 @@ TGIS = apple2-40-40-16.tgi apple2-280-192-6.tgi .PHONY: all clean zap -all: $(C_OBJS) $(S_OBJS) $(EMDS) $(JOYS) $(SERS) $(TGIS) +all: $(C_OBJS) $(S_OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS) ../runtime/zeropage.o: $(MAKE) -C $(dir $@) $(notdir $@) clean: - @$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) + @$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(MOUS:.mou=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) zap: clean - @$(RM) $(EMDS) $(JOYS) $(SERS) $(TGIS) - - + @$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS) diff --git a/libsrc/mouse/mouse-kernel.s b/libsrc/mouse/mouse-kernel.s index fc8d9490e..d568984a8 100644 --- a/libsrc/mouse/mouse-kernel.s +++ b/libsrc/mouse/mouse-kernel.s @@ -92,20 +92,25 @@ _mouse_install: ldy tmp1 bpl @L2 +; Install the IRQ vector if the driver needs it + + lda mouse_irq+2 ; Check high byte of IRQ vector + beq @L3 ; Jump if vector invalid + lda #$4C ; Jump opcode + sta mouse_irq ; Activate IRQ routine + ; Call driver install routine and check for errors - jsr mouse_install +@L3: jsr mouse_install tay ; Test error code - bne @L3 ; Bail out if install had errors + beq @L4 ; Jump if no error -; Install the IRQ vector if the driver needs it. A/X contains the error code -; from mouse_install, so don't use it. +; Uninstall IRQ vector if install routine had errors. A/X contains the error +; code from mouse_install, so don't use it. - ldy mouse_irq+2 ; Check high byte of IRQ vector - beq @L3 ; Jump if vector invalid - ldy #$4C ; Jump opcode - sty mouse_irq ; Activate IRQ routine -@L3: rts + ldy #$60 ; RTS opcode + sty mouse_irq ; Disable IRQ entry point +@L4: rts ; Driver signature invalid. One word is still on the stack diff --git a/samples/Makefile b/samples/Makefile index eaf28b703..2d03aaeea 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -71,7 +71,7 @@ all: $(EXELIST) ascii: $(CRT0) ascii.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ -diodemo: $(CRT0) diodemo.o $(CLIB) +diodemo: $(CRT0) diodemo.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ fire: $(CRT0) fire.o $(CLIB) @@ -85,20 +85,26 @@ hello: $(CRT0) hello.o $(CLIB) # The apple machines need the start address adjusted for the mandelbrot demo ifeq "$(SYS)" "apple2" -mandelbrot: $(CRT0) mandelbrot.o $(CLIB) +mandelbrot: $(CRT0) mandelbrot.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ else ifeq "$(SYS)" "apple2enh" -mandelbrot: $(CRT0) mandelbrot.o $(CLIB) +mandelbrot: $(CRT0) mandelbrot.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ else -mandelbrot: $(CRT0) mandelbrot.o $(CLIB) +mandelbrot: $(CRT0) mandelbrot.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ endif endif +# The Apple ][ needs the start address adjusted for the mousedemo +ifeq "$(SYS)" "apple2" +mousedemo: $(CRT0) mousedemo.o $(CLIB) + @$(LD) -t $(SYS) -m $(basename $@).map --start-addr 0x4000 -o $@ $^ +else mousedemo: $(CRT0) mousedemo.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -o $@ $^ +endif nachtm: $(CRT0) nachtm.o $(CLIB) @$(LD) -t $(SYS) -m $(basename $@).map -Ln $(basename $@).lbl -o $@ $^ diff --git a/samples/README b/samples/README index 420039966..dfe682c5b 100644 --- a/samples/README +++ b/samples/README @@ -66,7 +66,7 @@ Platforms: All systems with TGI support. You may have to change the Name: mousedemo Description: Shows how to use the mouse. Platforms: All systems with mouse and conio support: - C64, C128 + C64, C128, CBM510, Atari, Apple2 ----------------------------------------------------------------------------- Name: nachtm diff --git a/samples/mousedemo.c b/samples/mousedemo.c index 276bc2904..e3170dab3 100644 --- a/samples/mousedemo.c +++ b/samples/mousedemo.c @@ -1,5 +1,5 @@ /* - * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari + * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2 * * Ullrich von Bassewitz, 13.09.2001 * @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -61,6 +62,14 @@ static const unsigned char MouseSprite[64] = { #endif /* __C64__ or __C128__ */ +#ifdef __APPLE2__ +# define DRIVER "a2.stdmou.mou" +#endif + +#ifdef __APPLE2ENH__ +# define DRIVER "a2e.stdmou.mou" +#endif + static void CheckError (const char* S, unsigned char Error) @@ -81,7 +90,7 @@ static void DoWarning (void) " %s\n" "on disk! Press 'y' if you have it or\n" "any other key to exit.\n", DRIVER); - if (cgetc () != 'y') { + if (tolower (cgetc ()) != 'y') { exit (EXIT_SUCCESS); } printf ("Ok. Please wait patiently...\n"); @@ -113,9 +122,9 @@ int main (void) DoWarning (); /* Clear the screen, set white on black */ - bordercolor (COLOR_BLACK); - bgcolor (COLOR_BLACK); - textcolor (COLOR_GRAY3); + (void) bordercolor (COLOR_BLACK); + (void) bgcolor (COLOR_BLACK); + (void) textcolor (COLOR_GRAY3); cursor (0); clrscr (); -- 2.39.5