Merge branch 'master' into c1p

This commit is contained in:
Stephan Mühlstrasser
2013-07-26 22:56:37 +02:00
32 changed files with 1831 additions and 421 deletions

View File

@@ -1,15 +1,17 @@
;
; Ullrich von Bassewitz, 2003-04-13
; 2003-04-13, Ullrich von Bassewitz
; 2013-07-16, Greg King
;
; Screen size variables
;
.export screensize
.include "atmos.inc"
.proc screensize
ldx #40
ldy #28
ldx #SCREEN_XSIZE
ldy #SCREEN_YSIZE
rts
.endproc

View File

@@ -1,20 +1,24 @@
; Stefan Haubenthal, 2012-05-06
; based on code by Twilighte
; Based on code by Twilighte.
; 2012-05-06, Stefan Haubenthal
; 2013-07-22, Greg King
;
; void __fastcall__ atmos_load(const char* name);
.export _atmos_load
.import store_filename
.include "atmos.inc"
.proc _atmos_load
sei
jsr store_filename
ldx #$00
stx $02ad
stx $02ae
stx $025a
stx $025b
stx AUTORUN ; don't try to run the file
stx LANGFLAG ; BASIC
stx JOINFLAG ; don't join it to another BASIC program
stx VERIFYFLAG ; load the file
jsr cload_bit
cli
rts

View File

@@ -1,23 +1,27 @@
; Stefan Haubenthal, 2012-05-06
; based on code by Twilighte
; Based on code by Twilighte.
; 2012-05-06, Stefan Haubenthal
; 2013-07-22, Greg King
;
; void __fastcall__ atmos_save(const char* name, const void* start, const void* end);
.export _atmos_save
.import popax, store_filename
.include "atmos.inc"
.proc _atmos_save
sei
sta $02ab ; file end lo
stx $02ac ; file end hi
sta FILEEND
stx FILEEND+1
jsr popax
sta $02a9 ; file start lo
stx $02aa ; file start hi
sta FILESTART
stx FILESTART+1
jsr popax
jsr store_filename
lda #00
sta $02ad
sta AUTORUN
jsr csave_bit
cli
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 2003-04-13
; 2003-04-13, Ullrich von Bassewitz
; 2013-07-26, Greg King
;
; char cgetc (void);
;
@@ -11,7 +12,6 @@
.include "atmos.inc"
; ------------------------------------------------------------------------
;
@@ -41,8 +41,8 @@
@L2: and #$7F ; Mask out avail flag
sta KEYBUF
ldy $209
cpy #$A5
ldy MODEKEY
cpy #FUNCTKEY
bne @L3
ora #$80 ; FUNCT pressed

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 2003-04-13
; 2003-04-13, Ullrich von Bassewitz
; 2013-07-16, Greg King
;
.export _clrscr
@@ -27,7 +28,7 @@
; Clear full pages. Y is still zero
ldx #>(28*40)
ldx #>(SCREEN_YSIZE * SCREEN_XSIZE)
lda #' '
@L1: sta (ptr2),y
iny ; Bump low byte of address
@@ -40,7 +41,7 @@
@L2: sta (ptr2),y
iny
cpy #<(28*40)
cpy #<(SCREEN_YSIZE * SCREEN_XSIZE)
bne @L2
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 2003-04-13
; 2003-04-13, Ullrich von Bassewitz
; 2013-07-16, Greg King
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
@@ -41,7 +42,7 @@ output:
advance:
iny
cpy #40
cpy #SCREEN_XSIZE
bne L3
inc CURS_Y ; new line
ldy #0 ; + cr
@@ -85,12 +86,12 @@ L3: sty CURS_X
.rodata
ScrTabLo:
.repeat 28, Line
.byte <(SCREEN + Line * 40)
.repeat SCREEN_YSIZE, Line
.byte <(SCREEN + Line * SCREEN_XSIZE)
.endrep
ScrTabHi:
.repeat 28, Line
.byte >(SCREEN + Line * 40)
.repeat SCREEN_YSIZE, Line
.byte >(SCREEN + Line * SCREEN_XSIZE)
.endrep

View File

@@ -1,14 +1,15 @@
;
; P.A.S.E. joystick driver for the Atmos
; May be used multiple times when linked to the statically application.
; Can be used multiple times when statically linked to the application.
;
; Stefan Haubenthal, 2009-12-21
; Based on Ullrich von Bassewitz, 2002-12-20
; 2002-12-20, Based on Ullrich von Bassewitz's code.
; 2009-12-21, Stefan Haubenthal
; 2013-07-15, Greg King
;
.include "joy-kernel.inc"
.include "joy-error.inc"
; .include "atmos.inc"
.include "atmos.inc"
; ------------------------------------------------------------------------
@@ -49,10 +50,6 @@
JOY_COUNT = 2 ; Number of joysticks we support
PRA = $0301
DDRA = $0303
PRA2 = $030F
; ------------------------------------------------------------------------
; Data.
@@ -99,24 +96,24 @@ COUNT:
READ:
tay
lda PRA
lda VIA::PRA
pha
lda DDRA
lda VIA::DDRA
pha
lda #%11000000
sta DDRA
sta VIA::DDRA
lda #%10000000
sta PRA2
lda PRA2
sta VIA::PRA2
lda VIA::PRA2
sta temp1
lda #%01000000
sta PRA2
lda PRA
sta VIA::PRA2
lda VIA::PRA
sta temp2
pla
sta DDRA
sta VIA::DDRA
pla
sta PRA2
sta VIA::PRA2
ldx #0
tya

View File

@@ -1,19 +1,19 @@
;
; Ullrich von Bassewitz, 2003-03-07
; Stefan Haubenthal, 2011-01-28
; 2003-03-07, Ullrich von Bassewitz
; 2011-01-28, Stefan Haubenthal
; 2013-07-15, Greg King
;
; Setup arguments for main
;
.constructor initmainargs, 24
.import __argc, __argv
.include "atmos.inc"
.macpack generic
MAXARGS = 10 ; Maximum number of arguments allowed
REM = $9d ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name
BASIC_BUF = $35
FNAM = $293
;---------------------------------------------------------------------------
@@ -29,8 +29,8 @@ FNAM = $293
; Because the buffer, that we're copying into, was zeroed out,
; we don't need to add a NUL character.
;
ldy #NAME_LEN - 1 ; limit the length
L0: lda FNAM,y
ldy #FNAME_LEN - 1 ; limit the length
L0: lda CFOUND_NAME,y
sta name,y
dey
bpl L0
@@ -114,7 +114,7 @@ done: lda #<argv
;
.bss
term: .res 1
name: .res NAME_LEN + 1
name: .res FNAME_LEN + 1
.data
argv: .addr name

View File

@@ -2,7 +2,8 @@
; Serial driver for the Telestrat integrated serial controller and the
; Atmos with a serial add-on.
;
; Stefan Haubenthal, 2012-03-05
; 2012-03-05, Stefan Haubenthal
; 2013-07-15, Greg King
;
; The driver is based on the cc65 rs232 module, which in turn is based on
; Craig Bruce device driver for the Switftlink/Turbo-232.
@@ -25,6 +26,7 @@
.include "zeropage.inc"
.include "ser-kernel.inc"
.include "ser-error.inc"
.include "atmos.inc"
; ------------------------------------------------------------------------
; Header. Includes jump table
@@ -45,19 +47,10 @@
.addr CLOSE
.addr GET
.addr PUT
.addr STATUS
.addr SER_STATUS
.addr IOCTL
.addr IRQ
;----------------------------------------------------------------------------
; I/O definitions
ACIA = $031C
ACIA_DATA = ACIA+0 ; Data register
ACIA_STATUS = ACIA+1 ; Status register
ACIA_CMD = ACIA+2 ; Command register
ACIA_CTRL = ACIA+3 ; Control register
;----------------------------------------------------------------------------
; Global variables
@@ -142,7 +135,7 @@ CLOSE:
; Deactivate DTR and disable 6551 interrupts
lda #%00001010
sta ACIA_CMD,x
sta ACIA::CMD,x
; Done, return an error code
: lda #<SER_ERR_OK
@@ -194,10 +187,10 @@ OPEN:
lda StopTable,y
ora tmp1
ora #%00010000 ; Receiver clock source = baudrate
sta ACIA_CTRL
sta ACIA::CTRL
; Set the value for the command register. We remember the base value
; in RtsOff, since we will have to manipulate ACIA_CMD often.
; in RtsOff, since we will have to manipulate ACIA::CMD often.
ldy #SER_PARAMS::PARITY ; Parity
lda (ptr1),y
tay
@@ -205,7 +198,7 @@ OPEN:
ora #%00000001 ; DTR active
sta RtsOff
ora #%00001000 ; Enable receive interrupts
sta ACIA_CMD
sta ACIA::CMD
; Done
stx Index ; Mark port as open
@@ -252,7 +245,7 @@ GET:
sta Stopped
lda RtsOff
ora #%00001000
sta ACIA_CMD
sta ACIA::CMD
; Get byte from buffer
: ldy RecvHead ; (41)
@@ -296,11 +289,11 @@ PUT:
rts
;----------------------------------------------------------------------------
; STATUS: Return the status in the variable pointed to by ptr1.
; SER_STATUS: Return the status in the variable pointed to by ptr1.
; Must return an SER_ERR_xx code in a/x.
STATUS:
lda ACIA_STATUS
SER_STATUS:
lda ACIA::STATUS
ldx #$00
sta (ptr1,x)
txa ; SER_ERR_OK
@@ -325,10 +318,10 @@ IOCTL:
IRQ:
ldx Index ; Check for open port
beq Done
lda ACIA_STATUS,x ; Check ACIA status for receive interrupt
lda ACIA::STATUS,x ; Check ACIA status for receive interrupt
and #$08
beq Done ; Jump if no ACIA interrupt
lda ACIA_DATA,x ; Get byte from ACIA
lda ACIA::DATA,x ; Get byte from ACIA
ldy RecvFreeCnt ; Check if we have free space left
beq Flow ; Jump if no space in receive buffer
ldy RecvTail ; Load buffer pointer
@@ -342,7 +335,7 @@ IRQ:
; Assert flow control if buffer space too low
Flow: lda RtsOff
sta ACIA_CMD,x
sta ACIA::CMD,x
sta Stopped
sec ; Interrupt handled
Done: rts
@@ -361,7 +354,7 @@ Again: lda SendFreeCnt
bne Quit ; Bail out
; Check that ACIA is ready to send
lda ACIA_STATUS
lda ACIA::STATUS
and #$10
bne Send
bit tmp1 ; Keep trying if must try hard
@@ -371,7 +364,7 @@ Quit: rts
; Send byte and try again
Send: ldy SendHead
lda SendBuf,y
sta ACIA_DATA
sta ACIA::DATA
inc SendHead
inc SendFreeCnt
jmp Again

View File

@@ -1,12 +1,16 @@
; Helper function
.export store_filename
.importzp ptr1
.include "atmos.inc"
store_filename:
sta ptr1
stx ptr1+1
ldy #$0f ;store filename
ldy #FNAME_LEN - 1 ; store filename
: lda (ptr1),y
sta $027f,y
sta CFILE_NAME,y
dey
bpl :-
rts

View File

@@ -2,7 +2,7 @@
; Graphics driver for the 228x200x3 palette mode on the Atmos
;
; Stefan Haubenthal <polluks@sdf.lonestar.org>
; 2012-08-11, Greg King <greg.king5@verizon.net>
; 2013-07-15, Greg King <gregdk@users.sf.net>
;
.include "zeropage.inc"
@@ -79,21 +79,7 @@ ERROR: .res 1 ; Error code
MODE: .res 1 ; Graphics mode
PALETTE: .res 2
; Constants and table
; BASIC 1.1 addresses
PATTERN := $213
PARAM1 := $2E1 ; & $2E2
PARAM2 := $2E3 ; & $2E4
PARAM3 := $2E5 ; & $2E6
TEXT := $EC21
HIRES := $EC33
CURSET := $F0C8
CURMOV := $F0FD
DRAW := $F110
CHAR := $F12D
POINT := $F1C8
PAPER := $F204
INK := $F210
; Constant table
.rodata

View File

@@ -2,7 +2,7 @@
; Graphics driver for the 240x200x2 monochrome mode on the Atmos
;
; Stefan Haubenthal <polluks@sdf.lonestar.org>
; 2012-08-11, Greg King <greg.king5@verizon.net>
; 2013-07-16, Greg King <gregdk@users.sf.net>
;
.include "zeropage.inc"
@@ -66,10 +66,10 @@ YSIZE = 8 ; System font height
; Variables mapped to the zero page segment variables. Some of these are
; used for passing parameters to the driver.
X1 = ptr1
Y1 = ptr2
X2 = ptr3
Y2 = ptr4
X1 := ptr1
Y1 := ptr2
X2 := ptr3
Y2 := ptr4
; Absolute variables used in the code
@@ -78,19 +78,7 @@ Y2 = ptr4
ERROR: .res 1 ; Error code
MODE: .res 1 ; Graphics mode
; Constants and tables
PARAM1 = $2E1
PARAM2 = $2E3
PARAM3 = $2E5
TEXT = $EC21
HIRES = $EC33
CURSET = $F0C8
CURMOV = $F0FD
DRAW = $F110
CHAR = $F12D
POINT = $F1C8
PAPER = $F204
INK = $F210
; Constant table
.rodata
@@ -152,7 +140,7 @@ INIT:
; Must set an error code: NO
;
DONE = TEXT
DONE := TEXT
; ------------------------------------------------------------------------
; GETERROR: Return the error code in A and clear it.
@@ -170,7 +158,7 @@ GETERROR:
;
CONTROL:
sta $213
sta PATTERN
lda #TGI_ERR_OK
sta ERROR
rts
@@ -181,7 +169,7 @@ CONTROL:
; Must set an error code: NO
;
CLEAR = HIRES
CLEAR := HIRES
; ------------------------------------------------------------------------
; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).

View File

@@ -1,12 +1,18 @@
;
; Oliver Schmidt, 2013-05-31
; 2013-05-31, Oliver Schmidt
; 2013-06-11, Greg King
;
.export em_libref, joy_libref, mouse_libref, ser_libref, tgi_libref
.export em_libref
.export joy_libref
; .export mouse_libref
.export ser_libref
.export tgi_libref
.import _exit
em_libref := _exit
joy_libref := _exit
mouse_libref := _exit
;mouse_libref := _exit
ser_libref := _exit
tgi_libref := _exit

View File

@@ -0,0 +1,457 @@
;
; Driver for the Inkwell Systems 170-C and 184-C lightpens.
;
; 2013-07-01, Greg King
;
.include "zeropage.inc"
.include "mouse-kernel.inc"
.include "c128.inc"
.macpack generic
; ------------------------------------------------------------------------
; Header. Includes jump table.
.segment "JUMPTABLE"
HEADER:
; Driver signature
.byte $6d, $6f, $75 ; ASCII "mou"
.byte MOUSE_API_VERSION ; Mouse driver API version number
; Library reference
LIBREF: .addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr HIDE
.addr SHOW
.addr SETBOX
.addr GETBOX
.addr MOVE
.addr BUTTONS
.addr POS
.addr INFO
.addr IOCTL
.addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_EARLY_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 co-ord.
CMOVEY: jmp $0000 ; Move the cursor to Y co-ord.
;----------------------------------------------------------------------------
; Constants
; This driver is for the 40-column screen.
XSIZE = 40
YSIZE = 25
SCREEN_WIDTH = XSIZE * 8
SCREEN_HEIGHT = YSIZE * 8
;----------------------------------------------------------------------------
; Global variables. The bounding box values are sorted so that they can be
; written with the least effort in the SETBOX and GETBOX routines; so, don't
; re-order them.
.rodata
; Default values for below variables
; (We use ".proc" because we want to define both a label and a scope.)
.proc DefVars
.word 0 ; XMin
.word 0 ; YMin
.word SCREEN_WIDTH - 1 ; XMax
.word SCREEN_HEIGHT - 1 ; YMax
.byte %00000000 ; Buttons
.endproc
.bss
Vars:
XMin: .res 2 ; X1 value of bounding box
YMin: .res 2 ; Y1 value of bounding box
XMax: .res 2 ; X2 value of bounding box
YMax: .res 2 ; Y2 value of bounding box
Buttons: .res 1 ; Button status bits
XPos: .res 2 ; Current lightpen position, X
YPos: .res 2 ; Current lightpen position, Y
OldPenX: .res 1 ; Previous HW-counter values
OldPenY: .res 1
INIT_save: .res 1
.data
; Default Inkwell calibration.
; The first number is the width of the left border;
; the second number is the actual calibration value.
XOffset: .byte (24 + 24) / 2 ; x-offset
; Jump to a function that puts a new calibration value into XOffset.
Calibrate: jmp $0000
.code
;----------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present.
; Must return a MOUSE_ERR_xx code in .XA.
INSTALL:
; Disable the BASIC interpreter's interrupt-driven sprite-motion code.
; That allows direct access to the VIC-IIe's sprite registers.
lda INIT_STATUS
sta INIT_save
lda #%11000000
sta INIT_STATUS
; Initiate variables. Just copy the default stuff over.
ldx #.sizeof (DefVars) - 1
@L0: lda DefVars,x
sta Vars,x
dex
bpl @L0
ldx VIC_LPEN_X
ldy VIC_LPEN_Y
stx OldPenX
sty OldPenY
; Call a calibration function through the library-reference.
lda LIBREF
ldx LIBREF+1
sta ptr1 ; Point to mouse_adjuster
stx ptr1+1
ldy #1
lda (ptr1),y
bze @L1 ; Don't call pointer if it's NULL
sta Calibrate+2 ; Point to function
dey
lda (ptr1),y
sta Calibrate+1
lda #<XOffset ; Function will set this variable
ldx #>XOffset
jsr Calibrate
; Be sure that the lightpen cursor is invisible and at the default location.
; It needs to be done here because the lightpen interrupt handler doesn't
; set the lightpen position if it hasn't changed.
@L1: sei
jsr CHIDE
lda #<(SCREEN_HEIGHT / 2)
ldx #>(SCREEN_HEIGHT / 2)
jsr MoveY
lda #<(SCREEN_WIDTH / 2)
ldx #>(SCREEN_WIDTH / 2)
jsr MoveX
cli
; Done, return zero.
lda #MOUSE_ERR_OK
tax
rts
;----------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; No return code required (the driver is removed from memory on return).
UNINSTALL:
jsr HIDE ; Hide cursor on exit
lda INIT_save
sta INIT_STATUS
rts
;----------------------------------------------------------------------------
; HIDE routine. Is called to hide the lightpen pointer. The mouse kernel manages
; a counter for calls to show/hide, and the driver entry point is called only
; if the mouse is currently visible, and should get hidden. For most drivers,
; no special action is required besides hiding the lightpen cursor.
; No return code required.
HIDE: sei
jsr CHIDE
cli
rts
;----------------------------------------------------------------------------
; SHOW routine. Is called to show the lightpen pointer. The mouse kernel manages
; a counter for calls to show/hide, and the driver entry point is called only
; if the mouse is currently hidden, and should become visible. For most drivers,
; no special action is required besides enabling the lightpen cursor.
; No return code required.
SHOW: sei
jsr CSHOW
cli
rts
;----------------------------------------------------------------------------
; SETBOX: Set the lightpen bounding box. The parameters are passed as they come
; from the C program, that is, a pointer to a mouse_box struct in .XA.
; No checks are done if the lightpen is currently inside the box, that 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.
SETBOX: sta ptr1
stx ptr1+1 ; Save data pointer
ldy #.sizeof (MOUSE_BOX) - 1
sei
@L1: lda (ptr1),y
sta XMin,y
dey
bpl @L1
cli
rts
;----------------------------------------------------------------------------
; GETBOX: Return the lightpen bounding box. The parameters are passed as they
; come from the C program, that is, a pointer to a mouse_box struct in .XA.
GETBOX: sta ptr1
stx ptr1+1 ; Save data pointer
ldy #.sizeof (MOUSE_BOX) - 1
@L1: lda XMin,y
sta (ptr1),y
dey
bpl @L1
rts
;----------------------------------------------------------------------------
; 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 .XA. 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: sei ; No interrupts
jsr MoveY
ldy #$01
lda (sp),y
tax
dey
lda (sp),y
jsr MoveX ; Move the cursor
cli ; Allow interrupts
rts
;----------------------------------------------------------------------------
; BUTTONS: Return the button mask in .XA.
BUTTONS:
lda Buttons
ldx #>0
; Make the lightpen buttons look like a 1351 mouse.
asl a
asl SID_ADConv2 ; PotY
rol a
eor #MOUSE_BTN_RIGHT
and #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT
rts
;----------------------------------------------------------------------------
; POS: Return the lightpen position in the MOUSE_POS struct pointed to by ptr1.
; No return code required.
POS: ldy #MOUSE_POS::XCOORD ; Structure offset
sei ; Disable interrupts
lda XPos ; Transfer the position
sta (ptr1),y
lda XPos+1
iny
sta (ptr1),y
lda YPos
iny
sta (ptr1),y
lda YPos+1
cli ; Enable interrupts
iny
sta (ptr1),y ; Store last byte
rts
;----------------------------------------------------------------------------
; INFO: Returns lightpen position and current button mask in the MOUSE_INFO
; struct pointed to by ptr1. No return code required.
;
; We're cheating here, to keep the code smaller: The first fields of the
; mouse_info struct are identical to the mouse_pos struct; so, we'll just
; call _mouse_pos to initiate the struct pointer, and fill the position
; fields.
INFO: jsr POS
; Fill in the button state
jsr BUTTONS ; Will not touch ptr1
ldy #MOUSE_INFO::BUTTONS
sta (ptr1),y
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 error code in .XA.
;
IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioctls, for now
ldx #>MOUSE_ERR_INV_IOCTL
rts
;----------------------------------------------------------------------------
; IRQ: IRQ handler entry point. Called as a subroutine, but in the IRQ context
; (so, be careful). The routine MUST return carry set if the interrupt has been
; 'handled' -- which means that the interrupt source is gone. Otherwise, it
; MUST return carry clear.
;
IRQ:
; Record the state of the buttons.
; Try to avoid crosstalk between the keyboard and the lightpen.
ldy #%00000000 ; Set ports A and B to input
sty CIA1_DDRB
sty CIA1_DDRA ; Keyboard won't look like buttons
lda CIA1_PRB ; Read Control-Port 1
dec CIA1_DDRA ; Set port A back to output
eor #%11111111 ; Bit goes up when button goes down
sta Buttons
bze @L0
lda #%11101111 ; (Don't change bit that feeds VIC-II)
sta CIA1_DDRB ; Buttons won't look like keyboard
sty CIA1_PRB ; Set "all keys pushed"
; Read the VIC-II lightpen registers.
@L0: lda VIC_LPEN_Y
cmp OldPenY
; Skip processing if nothing has changed.
beq @SkipY
sta OldPenY
; Subtract the height of the top border, so that the lightpen co-ordinate
; will match the TGI co-ordinate.
sub #50
tay ; Remember low byte
ldx #>0
; Limit the Y co-ordinate to the bounding box.
txa
cpy YMin
sbc YMin+1
bpl @L3
ldy YMin
ldx YMin+1
jmp @L4
@L3: txa
cpy YMax
sbc YMax+1
bmi @L4
ldy YMax
ldx YMax+1
@L4: tya
jsr MoveY
@SkipY: lda VIC_LPEN_X
cmp OldPenX
; Skip processing if nothing has changed.
beq @SkipX
sta OldPenX
; Adjust the value by the calibration offset.
sub XOffset
; Calculate the new X co-ordinate.
; The VIC-II register is eight bits; but, the screen co-ordinate is nine bits.
; Therefore, the VIC-II number is doubled. Then, it points to every other pixel;
; but, it can reach across the screen.
asl a
tay ; Remember low byte
lda #>0
rol a
tax ; Remember high byte
; Limit the X co-ordinate to the bounding box.
cpy XMin
sbc XMin+1
bpl @L1
ldy XMin
ldx XMin+1
jmp @L2
@L1: txa
cpy XMax
sbc XMax+1
bmi @L2
ldy XMax
ldx XMax+1
@L2: tya
jsr MoveX
; Done
@SkipX: clc ; Interrupt not "handled"
rts
; Move the lightpen pointer to the new Y pos.
MoveY: sta YPos
stx YPos+1
jmp CMOVEY
; Move the lightpen pointer to the new X pos.
MoveX: sta XPos
stx XPos+1
jmp CMOVEX

23
libsrc/c128/mouseref.s Normal file
View File

@@ -0,0 +1,23 @@
;
; Pointer for library references by device drivers.
;
; 2013-07-25, Greg King
;
.export mouse_libref, _pen_adjuster
.data
mouse_libref: ; generic label for mouse-kernel
; A program optionally can set this pointer to a function that gives
; a calibration value to a driver. If this pointer isn't NULL,
; then a driver that wants a value can call that function.
;
; The function might read a value from a file; or, it might ask the user
; to help calibrate the driver.
;
; void __fastcall__ (*pen_adjuster)(unsigned char *) = NULL;
;
_pen_adjuster:
.addr $0000

93
libsrc/c128/pencalib.c Normal file
View File

@@ -0,0 +1,93 @@
/*
** Calibrate lightpen drivers to the current video hardware.
**
** 2013-07-25, Greg King
**
*/
#include <conio.h>
#include <mouse.h>
#include <pen.h>
#define COMMAND1 "Adjust by clicking on line."
#define COMMAND2 "Finish by clicking off bar."
/* There is a delay between when the VIC sends its signal, and when the display
** shows that signal. There is another delay between the display and when the
** lightpen says that it saw that signal. Each display and pen is different.
** Therefore, the driver must be calibrated to them. A white bar is painted on
** the screen; and, a line is drawn down the middle of it. When the user
** clicks on that line, the difference between its position and where the VIC
** thinks that the pen is pointing becomes an offset that is subtracted from
** what the VIC sees.
*/
void __fastcall__ pen_calibrate (unsigned char *XOffset)
{
unsigned char oldBg = bgcolor (COLOR_BLUE);
unsigned char oldText = textcolor (COLOR_GRAY3);
unsigned char oldRev = revers (1);
unsigned char sprite0Color = VIC.spr_color[0];
unsigned char width, width2, height, height4, height8;
struct mouse_info info;
screensize (&width, &height);
width2 = width / 2;
height4 = height / 4;
height8 = height4 * 8;
/* Draw a bar and line. */
clrscr ();
cclearxy (0, height4, height4 * width);
cvlinexy (width2, height4 + 1, height4 - 2);
/* Print instructions. */
revers (0);
cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1);
cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2);
VIC.spr_color[0] = COLOR_GRAY2;
mouse_show ();
mouse_move (width2 * 8, height8 / 2);
for (;;) {
/* Wait for the main button to be released. */
do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
/* Wait for the main button to be pressed. */
do {
mouse_info (&info);
} while (!(info.buttons & MOUSE_BTN_LEFT));
/* Find out if the pen is on or off the bar. */
if (info.pos.y < height8 || info.pos.y >= height8 * 2) {
break;
}
/* On the bar; adjust the offset. */
/* Characters are eight pixels wide.
** The VIC-II sees every other pixel;
** so, we use half of the difference.
*/
*XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2;
}
/* Off the bar; wait for the main button to be released. */
do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
mouse_hide ();
VIC.spr_color[0] = sprite0Color;
revers (oldRev);
textcolor (oldText);
bgcolor (oldBg);
clrscr ();
}

View File

@@ -1,12 +1,18 @@
;
; Oliver Schmidt, 2013-05-31
; 2013-05-31, Oliver Schmidt
; 2013-06-11, Greg King
;
.export em_libref, joy_libref, mouse_libref, ser_libref, tgi_libref
.export em_libref
.export joy_libref
; .export mouse_libref
.export ser_libref
.export tgi_libref
.import _exit
em_libref := _exit
joy_libref := _exit
mouse_libref := _exit
;mouse_libref := _exit
ser_libref := _exit
tgi_libref := _exit

View File

@@ -0,0 +1,438 @@
;
; Driver for the Inkwell Systems 170-C and 184-C lightpens.
;
; 2013-07-01, Greg King
;
.include "zeropage.inc"
.include "mouse-kernel.inc"
.include "c64.inc"
.macpack generic
; ------------------------------------------------------------------------
; Header. Includes jump table.
.segment "JUMPTABLE"
HEADER:
; Driver signature
.byte $6d, $6f, $75 ; ASCII "mou"
.byte MOUSE_API_VERSION ; Mouse driver API version number
; Library reference
LIBREF: .addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr HIDE
.addr SHOW
.addr SETBOX
.addr GETBOX
.addr MOVE
.addr BUTTONS
.addr POS
.addr INFO
.addr IOCTL
.addr IRQ
; Mouse driver flags
.byte MOUSE_FLAG_EARLY_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 co-ord.
CMOVEY: jmp $0000 ; Move the cursor to Y co-ord.
;----------------------------------------------------------------------------
; Constants
SCREEN_WIDTH = XSIZE * 8
SCREEN_HEIGHT = YSIZE * 8
;----------------------------------------------------------------------------
; Global variables. The bounding box values are sorted so that they can be
; written with the least effort in the SETBOX and GETBOX routines; so, don't
; re-order them.
.rodata
; Default values for below variables
; (We use ".proc" because we want to define both a label and a scope.)
.proc DefVars
.word 0 ; XMin
.word 0 ; YMin
.word SCREEN_WIDTH - 1 ; XMax
.word SCREEN_HEIGHT - 1 ; YMax
.byte %00000000 ; Buttons
.endproc
.bss
Vars:
XMin: .res 2 ; X1 value of bounding box
YMin: .res 2 ; Y1 value of bounding box
XMax: .res 2 ; X2 value of bounding box
YMax: .res 2 ; Y2 value of bounding box
Buttons: .res 1 ; Button status bits
XPos: .res 2 ; Current lightpen position, X
YPos: .res 2 ; Current lightpen position, Y
OldPenX: .res 1 ; Previous HW-counter values
OldPenY: .res 1
.data
; Default Inkwell calibration.
; The first number is the width of the left border;
; the second number is the actual calibration value.
XOffset: .byte (24 + 24) / 2 ; x-offset
; Jump to a function that puts a new calibration value into XOffset.
Calibrate: jmp $0000
.code
;----------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present.
; Must return a MOUSE_ERR_xx code in .XA.
INSTALL:
; Initiate variables. Just copy the default stuff over.
ldx #.sizeof (DefVars) - 1
@L0: lda DefVars,x
sta Vars,x
dex
bpl @L0
ldx VIC_LPEN_X
ldy VIC_LPEN_Y
stx OldPenX
sty OldPenY
; Call a calibration function through the library-reference.
lda LIBREF
ldx LIBREF+1
sta ptr1 ; Point to mouse_adjuster
stx ptr1+1
ldy #1
lda (ptr1),y
bze @L1 ; Don't call pointer if it's NULL
sta Calibrate+2 ; Point to function
dey
lda (ptr1),y
sta Calibrate+1
lda #<XOffset ; Function will set this variable
ldx #>XOffset
jsr Calibrate
; Be sure that the lightpen cursor is invisible and at the default location.
; It needs to be done here because the lightpen interrupt handler doesn't
; set the lightpen position if it hasn't changed.
@L1: sei
jsr CHIDE
lda #<(SCREEN_HEIGHT / 2)
ldx #>(SCREEN_HEIGHT / 2)
jsr MoveY
lda #<(SCREEN_WIDTH / 2)
ldx #>(SCREEN_WIDTH / 2)
jsr MoveX
cli
; Done, return zero.
lda #MOUSE_ERR_OK
tax
rts
;----------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; No return code required (the driver is removed from memory on return).
UNINSTALL := HIDE ; Hide cursor on exit
;----------------------------------------------------------------------------
; HIDE routine. Is called to hide the lightpen pointer. The mouse kernel manages
; a counter for calls to show/hide, and the driver entry point is called only
; if the mouse is currently visible, and should get hidden. For most drivers,
; no special action is required besides hiding the lightpen cursor.
; No return code required.
HIDE: sei
jsr CHIDE
cli
rts
;----------------------------------------------------------------------------
; SHOW routine. Is called to show the lightpen pointer. The mouse kernel manages
; a counter for calls to show/hide, and the driver entry point is called only
; if the mouse is currently hidden, and should become visible. For most drivers,
; no special action is required besides enabling the lightpen cursor.
; No return code required.
SHOW: sei
jsr CSHOW
cli
rts
;----------------------------------------------------------------------------
; SETBOX: Set the lightpen bounding box. The parameters are passed as they come
; from the C program, that is, a pointer to a mouse_box struct in .XA.
; No checks are done if the lightpen is currently inside the box, that 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.
SETBOX: sta ptr1
stx ptr1+1 ; Save data pointer
ldy #.sizeof (MOUSE_BOX) - 1
sei
@L1: lda (ptr1),y
sta XMin,y
dey
bpl @L1
cli
rts
;----------------------------------------------------------------------------
; GETBOX: Return the lightpen bounding box. The parameters are passed as they
; come from the C program, that is, a pointer to a mouse_box struct in .XA.
GETBOX: sta ptr1
stx ptr1+1 ; Save data pointer
ldy #.sizeof (MOUSE_BOX) - 1
@L1: lda XMin,y
sta (ptr1),y
dey
bpl @L1
rts
;----------------------------------------------------------------------------
; 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 .XA. 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: sei ; No interrupts
jsr MoveY
ldy #$01
lda (sp),y
tax
dey
lda (sp),y
jsr MoveX ; Move the cursor
cli ; Allow interrupts
rts
;----------------------------------------------------------------------------
; BUTTONS: Return the button mask in .XA.
BUTTONS:
lda Buttons
ldx #>0
; Make the lightpen buttons look like a 1351 mouse.
asl a
asl SID_ADConv2 ; PotY
rol a
eor #MOUSE_BTN_RIGHT
and #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT
rts
;----------------------------------------------------------------------------
; POS: Return the lightpen position in the MOUSE_POS struct pointed to by ptr1.
; No return code required.
POS: ldy #MOUSE_POS::XCOORD ; Structure offset
sei ; Disable interrupts
lda XPos ; Transfer the position
sta (ptr1),y
lda XPos+1
iny
sta (ptr1),y
lda YPos
iny
sta (ptr1),y
lda YPos+1
cli ; Enable interrupts
iny
sta (ptr1),y ; Store last byte
rts
;----------------------------------------------------------------------------
; INFO: Returns lightpen position and current button mask in the MOUSE_INFO
; struct pointed to by ptr1. No return code required.
;
; We're cheating here, to keep the code smaller: The first fields of the
; mouse_info struct are identical to the mouse_pos struct; so, we'll just
; call _mouse_pos to initiate the struct pointer, and fill the position
; fields.
INFO: jsr POS
; Fill in the button state
jsr BUTTONS ; Will not touch ptr1
ldy #MOUSE_INFO::BUTTONS
sta (ptr1),y
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 error code in .XA.
;
IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioctls, for now
ldx #>MOUSE_ERR_INV_IOCTL
rts
;----------------------------------------------------------------------------
; IRQ: IRQ handler entry point. Called as a subroutine, but in the IRQ context
; (so, be careful). The routine MUST return carry set if the interrupt has been
; 'handled' -- which means that the interrupt source is gone. Otherwise, it
; MUST return carry clear.
;
IRQ:
; Record the state of the buttons.
; Try to avoid crosstalk between the keyboard and the lightpen.
ldy #%00000000 ; Set ports A and B to input
sty CIA1_DDRB
sty CIA1_DDRA ; Keyboard won't look like buttons
lda CIA1_PRB ; Read Control-Port 1
dec CIA1_DDRA ; Set port A back to output
eor #%11111111 ; Bit goes up when button goes down
sta Buttons
bze @L0
lda #%11101111 ; (Don't change bit that feeds VIC-II)
sta CIA1_DDRB ; Buttons won't look like keyboard
sty CIA1_PRB ; Set "all keys pushed"
; Read the VIC-II lightpen registers.
@L0: lda VIC_LPEN_Y
cmp OldPenY
; Skip processing if nothing has changed.
beq @SkipY
sta OldPenY
; Subtract the height of the top border, so that the lightpen co-ordinate
; will match the TGI co-ordinate.
sub #50
tay ; Remember low byte
ldx #>0
; Limit the Y co-ordinate to the bounding box.
txa
cpy YMin
sbc YMin+1
bpl @L3
ldy YMin
ldx YMin+1
jmp @L4
@L3: txa
cpy YMax
sbc YMax+1
bmi @L4
ldy YMax
ldx YMax+1
@L4: tya
jsr MoveY
@SkipY: lda VIC_LPEN_X
cmp OldPenX
; Skip processing if nothing has changed.
beq @SkipX
sta OldPenX
; Adjust the value by the calibration offset.
sub XOffset
; Calculate the new X co-ordinate.
; The VIC-II register is eight bits; but, the screen co-ordinate is nine bits.
; Therefore, the VIC-II number is doubled. Then, it points to every other pixel;
; but, it can reach across the screen.
asl a
tay ; Remember low byte
lda #>0
rol a
tax ; Remember high byte
; Limit the X co-ordinate to the bounding box.
cpy XMin
sbc XMin+1
bpl @L1
ldy XMin
ldx XMin+1
jmp @L2
@L1: txa
cpy XMax
sbc XMax+1
bmi @L2
ldy XMax
ldx XMax+1
@L2: tya
jsr MoveX
; Done
@SkipX: clc ; Interrupt not "handled"
rts
; Move the lightpen pointer to the new Y pos.
MoveY: sta YPos
stx YPos+1
jmp CMOVEY
; Move the lightpen pointer to the new X pos.
MoveX: sta XPos
stx XPos+1
jmp CMOVEX

23
libsrc/c64/mouseref.s Normal file
View File

@@ -0,0 +1,23 @@
;
; Pointer for library references by device drivers.
;
; 2013-07-25, Greg King
;
.export mouse_libref, _pen_adjuster
.data
mouse_libref: ; generic label for mouse-kernel
; A program optionally can set this pointer to a function that gives
; a calibration value to a driver. If this pointer isn't NULL,
; then a driver that wants a value can call that function.
;
; The function might read a value from a file; or, it might ask the user
; to help calibrate the driver.
;
; void __fastcall__ (*pen_adjuster)(unsigned char *) = NULL;
;
_pen_adjuster:
.addr $0000

94
libsrc/c64/pencalib.c Normal file
View File

@@ -0,0 +1,94 @@
/*
** Calibrate lightpen drivers to the current video hardware.
**
** 2013-07-25, Greg King
**
*/
#include <conio.h>
#include <mouse.h>
#include <pen.h>
#define COMMAND1 "Adjust by clicking on line."
#define COMMAND2 "Finish by clicking off bar."
/*
** There is a delay between when the VIC sends its signal, and when the display
** shows that signal. There is another delay between the display and when
** the lightpen says that it saw that signal. Each display and pen is different.
** Therefore, the driver must be calibrated to them. A white bar is painted on
** the screen; and, a line is drawn down the middle of it. When the user clicks
** on that line, the difference between its position and where the VIC thinks
** that the pen is pointing becomes an offset that is subtracted from what the
** VIC sees.
*/
void __fastcall__ pen_calibrate (unsigned char *XOffset)
{
unsigned char oldBg = bgcolor (COLOR_BLUE);
unsigned char oldText = textcolor (COLOR_GRAY3);
unsigned char oldRev = revers (1);
unsigned char sprite0Color = VIC.spr_color[0];
unsigned char width, width2, height, height4, height8;
struct mouse_info info;
screensize (&width, &height);
width2 = width / 2;
height4 = height / 4;
height8 = height4 * 8;
/* Draw a bar and line. */
clrscr ();
cclearxy (0, height4, height4 * width);
cvlinexy (width2, height4 + 1, height4 - 2);
revers (0);
/* Print instructions. */
cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1);
cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2);
VIC.spr_color[0] = COLOR_GRAY2;
mouse_show ();
mouse_move (width2 * 8, height8 / 2);
for (;;) {
/* Wait for the main button to be released. */
do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
/* Wait for the main button to be pressed. */
do {
mouse_info (&info);
} while (!(info.buttons & MOUSE_BTN_LEFT));
/* Find out if the pen is on or off the bar. */
if (info.pos.y < height8 || info.pos.y >= height8 * 2) {
break;
}
/* On the bar; adjust the offset. */
/* Characters are eight pixels wide.
** The VIC-II sees every other pixel;
** so, we use half of the difference.
*/
*XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2;
}
/* Off the bar; wait for the main button to be released. */
do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
mouse_hide ();
VIC.spr_color[0] = sprite0Color;
revers (oldRev);
textcolor (oldText);
bgcolor (oldBg);
clrscr ();
}

54
libsrc/cbm/penadjust.c Normal file
View File

@@ -0,0 +1,54 @@
/*
** Main lightpen driver calibration functions.
**
** 2013-07-25, Greg King
*/
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
#include <pen.h>
static const char *name;
/* Get a lightpen calibration value from a file if it exists. Otherwise, call
** pen_calibrate() to create a value; then, write it into a file, so that it
** will be available at the next time that the lightpen is used.
** Might change the screen.
*/
static void __fastcall__ adjuster (unsigned char *XOffset)
{
int fd = open (name, O_RDONLY);
if (fd < 0) {
pen_calibrate (XOffset);
fd = open (name, O_WRONLY | O_CREAT | O_EXCL);
if (fd >= 0) {
(void) write (fd, XOffset, 1);
close (fd);
}
} else {
(void) read (fd, XOffset, 1);
close (fd);
}
}
/* pen_adjust() is optional; if you want to use its feature,
** then it must be called before a driver is installed.
** Note: This function merely saves the file-name pointer, and sets
** the pen_adjuster pointer. The file will be read only when a driver
** is installed, and only if that driver wants to be calibrated.
*/
void __fastcall__ pen_adjust (const char *filename)
{
if (filename != NULL && filename[0] != '\0') {
name = filename;
pen_adjuster = adjuster;
} else {
pen_adjuster = pen_calibrate;
}
}