Merge remote-tracking branch 'upstream/master' into a5200

This commit is contained in:
Christian Groessler
2014-04-25 02:07:44 +02:00
67 changed files with 1685 additions and 809 deletions

View File

@@ -31,3 +31,7 @@ CA65FLAGS += -D NUMDRVS=4 -D LINEBUF=80 -D UCASE_FILENAME=1 -D DEFAULT_DEVICE=1
# Disabled by default, you should enable it if the linker script relocates the
# character generator (like atarixl-largehimem.cfg).
#CA65FLAGS += -D CHARGEN_RELOC -D USEWSYNC
# Disable if you don't want to use page 6 for mouse P/M data.
# If disabled, top of the RAM is used for P/M data.
CA65FLAGS += -D USE_PAGE6

View File

@@ -2,19 +2,14 @@
; Oliver Schmidt, 2013-05-31
;
.export em_libref, joy_libref, tgi_libref, ser_libref, mouse_libref
.export em_libref, joy_libref, tgi_libref
.import _exit
.import atari_ser_libref
em_libref := _exit
joy_libref := _exit
ser_libref := atari_ser_libref
.ifdef __ATARIXL__
.import CIO_handler
tgi_libref := CIO_handler
.import set_VTIMR1_handler
mouse_libref := set_VTIMR1_handler
.else
mouse_libref := _exit
tgi_libref := _exit
.endif

View File

@@ -1,126 +1,8 @@
;
; Default mouse callbacks for the Ataris
;
; Christian Groessler, 03.01.2014
;
; derived from Apple2 version by
; Oliver Schmidt, 22.09.2005
;
; All functions in this module should be interrupt safe, because they may
; be called from an interrupt handler
; This file defines the default mouse callback
;
.export _mouse_def_callbacks
.importzp tmp4
.import mul40,loc_tmp
.import _mouse_pm_callbacks
.export _mouse_def_callbacks
.include "atari.inc"
; ------------------------------------------------------------------------
.bss
backup: .res 1
visible:.res 1
; ------------------------------------------------------------------------
.segment "EXTZP" : zeropage
scrptr: .res 2
; ------------------------------------------------------------------------
.rodata
; Callback structure
_mouse_def_callbacks:
.addr hide
.addr show
.addr prep
.addr draw
.addr movex
.addr movey
; ------------------------------------------------------------------------
.data
cursor = 11 ; '+' screen code'
; setcursor
getcursor:
column: ldy #$00 ; Patched at runtime
lda (scrptr),y
rts
setcursor:
column2:ldy #$00 ; Patched at runtime
sta (scrptr),y
rts
; ------------------------------------------------------------------------
.code
done:
rts
; Hide the mouse cursor.
hide:
dec visible
prep:
jsr getcursor ; Get character at cursor position
cmp #cursor ; "mouse" character
bne overwr ; no, probably program has overwritten it
lda backup ;
jmp setcursor ; Draw character
overwr: sta backup
rts
; Show the mouse cursor.
show:
inc visible
draw:
lda visible
beq done
jsr getcursor ; Cursor visible at current position?
sta backup ; Save character at cursor position
lda #cursor
jmp setcursor ; Draw cursor
; Move the mouse cursor x position to the value in A/X.
movex:
cpx #1
ror a
lsr a ; convert to character position
lsr a
sta column+1
sta column2+1
rts
; Move the mouse cursor y position to the value in A/X.
movey:
tax
ldy tmp4 ; mul40 uses tmp4
lda loc_tmp ; and this local variable
pha
txa ; get parameter back
lsr a ; convert y position to character line
lsr a
lsr a
jsr mul40
clc
adc SAVMSC
sta scrptr
txa
adc SAVMSC+1
sta scrptr+1
pla
sta loc_tmp
sty tmp4
rts
_mouse_def_callbacks := _mouse_pm_callbacks

View File

@@ -0,0 +1,31 @@
;
; P/M mouse shape default definition
;
; Christian Groessler, 11.04.2014
;
; Note that the height of the mouse cursor must not exceed 32
; lines, otherwise the display routines won't do The Right
; Thing(tm).
;
.export mouse_pm_bits
.export mouse_pm_height : zeropage
.export mouse_pm_hotspot_x : zeropage
.export mouse_pm_hotspot_y : zeropage
.rodata
mouse_pm_bits:
.byte %11110000
.byte %11000000
.byte %10100000
.byte %10010000
.byte %10001000
.byte %00000100
.byte %00000010
mouse_pm_height = * - mouse_pm_bits
; hot spot is upper left corner
mouse_pm_hotspot_x = 0
mouse_pm_hotspot_y = 0

237
libsrc/atari/mcbpm.s Normal file
View File

@@ -0,0 +1,237 @@
;
; P/M mouse callbacks for the Ataris
;
; Christian Groessler, 11.04.2014
;
; All functions in this module should be interrupt safe, because they may
; be called from an interrupt handler
;
.include "atari.inc"
.importzp sp
.export _mouse_pm_callbacks
.constructor pm_init,27
.destructor pm_down,7
; get mouse shape data
.import mouse_pm_bits
.importzp mouse_pm_height
.importzp mouse_pm_hotspot_x
.importzp mouse_pm_hotspot_y
; P/M definitions. The MOUSE_PM_NUM value can be changed to adjust the
; number of the P/M used for the mouse. All others depend on this value.
; Valid P/M numbers are 0 to 4. When 4 is used, the missiles are used
; as a player.
.ifdef USE_PAGE6
MOUSE_PM_NUM = 2 ; P/M used for the mouse
; This cannot be changed since only player #2 uses the memory at $600.
.else
MOUSE_PM_NUM = 4 ; P/M used for the mouse
; Using player #4 (missiles) wastes the least amount of memory on the
; atari target, since top of memory is typically at $xC20, and the
; missiles use the space at $xB00-$xBFF.
; On the atarixl target this configuration (not using page 6) is not
; really satisfying since the top of memory typically lies beneath
; the ROM and there is flickering visible while the ROM is banked in.
.endif
MOUSE_PM_BASE = pm_base ; ZP location pointing to the hw area used by the selected P/M
.if MOUSE_PM_NUM = 4
MOUSE_PM_RAW = 0 ; MOUSE_PM_RAW is the hardware P/M number for MOUSE_PM_NUM
.macro set_mouse_x
; assume CF = 0
sta HPOSM3
adc #2
sta HPOSM2
adc #2
sta HPOSM1
adc #2
sta HPOSM0
.endmacro
.else
MOUSE_PM_RAW = MOUSE_PM_NUM + 1
.macro set_mouse_x
sta HPOSP0 + MOUSE_PM_NUM
.endmacro
.endif
; ------------------------------------------------------------------------
.rodata
; Callback structure
_mouse_pm_callbacks:
.addr hide
.addr show
.addr prep
.addr draw
.addr movex
.addr movey
; ------------------------------------------------------------------------
.bss
omy: .res 1 ; old Mouse Y position
colhlp: .res 1 ; helper variable to set P/M color
; ------------------------------------------------------------------------
.segment "EXTZP" : zeropage
pm_base:.res 2
; ------------------------------------------------------------------------
.code
; Hide the mouse cursor.
hide: lda #0
sta GRACTL
rts
; Show the mouse cursor.
show:
.if MOUSE_PM_NUM < 4
lda #2
.else
lda #1
.endif
sta GRACTL
jmp update_colors
prep:
draw:
rts
; Move the mouse cursor x position to the value in A/X.
movex: cpx #1
ror a
clc
adc #48
sbc #(mouse_pm_hotspot_x - 1) & $FF
set_mouse_x
jmp update_colors
; Move the mouse cursor y position to the value in A/X.
movey: clc
adc #32
sbc #(mouse_pm_hotspot_y - 1) & $FF
pha
lda omy
jsr clr_pm ; remove player at old position
jsr update_colors
pla
sta omy
;jmp set_pm ; put player to new position
; fall thru
; Set P/M data from 'mouse_pm_bits'
set_pm: tay
ldx #0
set_l: lda mouse_pm_bits,x
sta (MOUSE_PM_BASE),y
inx
iny
beq set_end
cpx #mouse_pm_height
bcc set_l
set_end:rts
; Clear (zero) P/M data
clr_pm: ldx #mouse_pm_height
tay
lda #0
clr_l: sta (MOUSE_PM_BASE),y
iny
beq clr_end
dex
bne clr_l
clr_end:rts
pm_down = hide
; this assumes a GRAPHICS 0 screen
update_colors:
lda COLOR2 ; get background color
and #$F0
sta colhlp
lda COLOR1
and #$0F
ora colhlp
.if MOUSE_PM_NUM = 4
sta PCOLR0
sta PCOLR1
sta PCOLR2
sta PCOLR3
lda #0
sta SIZEM
.else
sta PCOLR0 + MOUSE_PM_NUM
lda #0
sta SIZEP0 + MOUSE_PM_NUM
.endif
rts
; ------------------------------------------------------------------------
.segment "INIT"
pm_init:
lda #0
.ifdef USE_PAGE6
sta MOUSE_PM_BASE
ldx #6 ; page 6
stx MOUSE_PM_BASE+1
.else
; use top of memory and lower sp accordingly
sta sp
sta MOUSE_PM_BASE
lda sp+1
and #7 ; offset within 2K
cmp #3 + MOUSE_PM_RAW + 1 ; can we use it?
bcc @decr ; no
lda sp+1
and #$F8
@set: adc #3 + MOUSE_PM_RAW - 1 ; CF is set, so adding MOUSE_PM_RAW + 3
sta MOUSE_PM_BASE+1
sta sp+1
bne @cont ; jump always
@decr: lda sp+1
and #$F8
sbc #8 - 1 ; CF is clear, subtracts 8
bcs @set ; jump always
@cont: lda #0
.endif
tay
@iniloo:sta (MOUSE_PM_BASE),y
iny
bne @iniloo
.ifndef USE_PAGE6
lda MOUSE_PM_BASE+1
and #$F8
.endif
sta PMBASE
lda #62
sta SDMCTL
lda #1
sta GPRIOR
jmp update_colors

View File

@@ -0,0 +1,7 @@
;
; Default text mode mouse cursor character
;
; Christian Groessler, 11.04.2014
;
.export mouse_txt_char : zp = 96 ; 'diamond' screen code

125
libsrc/atari/mcbtxtchar.s Normal file
View File

@@ -0,0 +1,125 @@
;
; Text mode character mouse callbacks for the Ataris
;
; Christian Groessler, 03.01.2014
;
; derived from Apple2 version by
; Oliver Schmidt, 22.09.2005
;
; All functions in this module should be interrupt safe, because they may
; be called from an interrupt handler
;
.export _mouse_txt_callbacks
.importzp tmp4
.import mul40,loc_tmp
.importzp mouse_txt_char ; screen code of mouse cursor
.include "atari.inc"
; ------------------------------------------------------------------------
.bss
backup: .res 1
visible:.res 1
; ------------------------------------------------------------------------
.segment "EXTZP" : zeropage
scrptr: .res 2
; ------------------------------------------------------------------------
.rodata
; Callback structure
_mouse_txt_callbacks:
.addr hide
.addr show
.addr prep
.addr draw
.addr movex
.addr movey
; ------------------------------------------------------------------------
.data
; setcursor
getcursor:
column: ldy #$00 ; Patched at runtime
lda (scrptr),y
rts
setcursor:
column2:ldy #$00 ; Patched at runtime
sta (scrptr),y
rts
; ------------------------------------------------------------------------
.code
done:
rts
; Hide the mouse cursor.
hide:
dec visible
prep:
jsr getcursor ; Get character at cursor position
cmp #mouse_txt_char ; "mouse" character
bne overwr ; no, probably program has overwritten it
lda backup ;
jmp setcursor ; Draw character
overwr: sta backup
rts
; Show the mouse cursor.
show:
inc visible
draw:
lda visible
beq done
jsr getcursor ; Cursor visible at current position?
sta backup ; Save character at cursor position
lda #mouse_txt_char
jmp setcursor ; Draw cursor
; Move the mouse cursor x position to the value in A/X.
movex:
cpx #1
ror a
lsr a ; convert to character position
lsr a
sta column+1
sta column2+1
rts
; Move the mouse cursor y position to the value in A/X.
movey:
tax
ldy tmp4 ; mul40 uses tmp4
lda loc_tmp ; and this local variable
pha
txa ; get parameter back
lsr a ; convert y position to character line
lsr a
lsr a
jsr mul40
clc
adc SAVMSC
sta scrptr
txa
adc SAVMSC+1
sta scrptr+1
pla
sta loc_tmp
sty tmp4
rts

13
libsrc/atari/mouseref.s Normal file
View File

@@ -0,0 +1,13 @@
;
; Christian Groessler, 2014-04-22
;
.export mouse_libref
.ifdef __ATARIXL__
.import set_VTIMR1_handler
mouse_libref := set_VTIMR1_handler
.else
.import _exit
mouse_libref := _exit
.endif

View File

@@ -1,7 +1,12 @@
;
; Christian Groessler, 2014-04-22
;
.include "atari.inc"
.include "atari.inc"
.import _close, pushax, popax
.export ser_libref
.import _close, pushax, popax
.import findfreeiocb
.import __do_oserror
.import fddecusage
@@ -10,19 +15,19 @@
.import clriocb
.import newfd
.export atari_ser_libref
ser_libref := atari_ser_libref
.rodata
atari_ser_libref:
.word newfd
.word _close
.word pushax
.word popax
.word newfd
.word _close
.word pushax
.word popax
.word findfreeiocb
.word __do_oserror
.word fddecusage
.word fdtoiocb
.word __inviocb
.word clriocb
.word CIOV
.word CIOV

View File

@@ -21,7 +21,7 @@
tax
jsr isdisk
bcc open
lda #9 ; "Ilegal device"
lda #9 ; "Illegal device"
rts
; Open channel

View File

@@ -48,7 +48,7 @@ __sys_oserrlist:
sys_oserr_entry 6, "File not input"
sys_oserr_entry 7, "File not output"
sys_oserr_entry 8, "Filename missing"
sys_oserr_entry 9, "Ilegal device"
sys_oserr_entry 9, "Illegal device"
sys_oserr_entry 20, "Read error"
sys_oserr_entry 21, "Read error"
sys_oserr_entry 22, "Read error"

View File

@@ -40,7 +40,7 @@ ErrTab:
.byte 6, EINVAL ; File not input
.byte 7, EINVAL ; File not output
.byte 8, EINVAL ; Filename missing
.byte 9, ENODEV ; Ilegal device
.byte 9, ENODEV ; Illegal device
; .byte 20, ; Read error
; .byte 21, ; Read error
; .byte 22, ; Read error

View File

@@ -74,7 +74,7 @@ init: txa
; Return with error in A
err: lda #9 ; "Ilegal device"
err: lda #9 ; "Illegal device"
done: rts
.endproc
@@ -92,4 +92,4 @@ done: rts
@L0: cmp #10
rts
.endproc
.endproc

View File

@@ -1,24 +1,156 @@
; mainargs.s
;
; Ullrich von Bassewitz, 2003-03-07
; 2003-03-07, Ullrich von Bassewitz,
; based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2005-02-26, Ullrich von Bassewitz
; 2014-04-02, Greg King
;
; Setup arguments for main
; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument.
; Send, to main(), that array and the count of the arguments.
;
; Command-lines look like these lines:
;
; run
; run : rem
; run:rem arg1 " arg 2 is quoted " arg3 "" arg5
;
; "run" and "rem" are entokenned; the args. are not. Leading and trailing
; spaces outside of quotes are ignored.
;
; TO-DO:
; - The "file-name" might be a path-name; don't copy the directory-components.
; - Add a control-character quoting mechanism.
.constructor initmainargs, 24
.import __argc, __argv
.import sys_bank, restore_bank
.import sysp0:zp, ptr1:zp
.include "cbm510.inc"
.macpack generic
;---------------------------------------------------------------------------
MAXARGS = 10 ; Maximum number of arguments allowed
REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name
; Get possible command-line arguments. Goes into the special INIT segment,
; which may be reused after the startup code is run
; which may be reused after the startup code is run.
;
.segment "INIT"
.proc initmainargs
initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD
; statement. Save the "most-recent filename" as argument #0.
; Because the buffer, that we're copying into, was zeroed out,
; we don't need to add a NUL character.
;
jsr sys_bank
ldy #FNAM
lda (sysp0),y ; Get file-name pointer from system bank
sta ptr1
iny
lda (sysp0),y
sta ptr1+1
iny ; FNAM_BANK
lda (sysp0),y
tax
ldy #FNAM_LEN
lda (sysp0),y
tay
stx IndReg ; Look for name in correct bank
cpy #NAME_LEN + 1
blt L1
ldy #NAME_LEN - 1 ; limit the length
L0: lda (ptr1),y
sta name,y
L1: dey
bpl L0
jsr restore_bank
inc __argc ; argc always is equal to at least 1
; Find a "rem" token.
;
ldx #0
L2: lda BASIC_BUF,x
bze done ; no "rem," no args.
inx
cmp #REM
bne L2
ldy #1 * 2
; Find the next argument.
;
next: lda BASIC_BUF,x
bze done ; End of line reached
inx
cmp #' ' ; Skip leading spaces
beq next ;
; Found start of next argument. We've incremented the pointer in X already, so
; it points to the second character of the argument. That is useful because we
; will check now for a quoted argument; in which case, we will have to skip that
; first character.
;
found: cmp #'"' ; Is the argument quoted?
beq setterm ; Jump if so
dex ; Reset pointer to first argument character
lda #' ' ; A space ends the argument
setterm:sta term ; Set end-of-argument marker
; Now, store a pointer to the argument into the next slot.
;
txa ; Get low byte
add #<BASIC_BUF
sta argv,y ; argv[y]= &arg
lda #>0
adc #>BASIC_BUF
sta argv+1,y
iny
iny
inc __argc ; Found another arg
; Search for the end of the argument.
;
argloop:lda BASIC_BUF,x
bze done
inx
cmp term
bne argloop
; We've found the end of the argument. X points one character behind it, and
; A contains the terminating character. To make the argument a valid C string,
; replace the terminating character by a zero.
;
lda #0
sta BASIC_BUF-1,x
; Check if the maximum number of command-line arguments is reached. If not,
; parse the next one.
;
lda __argc ; Get low byte of argument count
cmp #MAXARGS ; Maximum number of arguments reached?
blt next ; Parse next one if not
; (The last vector in argv[] already is NULL.)
;
done: lda #<argv
ldx #>argv
sta __argv
stx __argv + 1
rts
.endproc
; These arrays are zeroed before initmainargs is called.
; char name[16+1];
; char* argv[MAXARGS+1]={name};
;
.bss
term: .res 1
name: .res NAME_LEN + 1
.data
argv: .addr name
.res MAXARGS * 2, 0

View File

@@ -1,24 +1,156 @@
; mainargs.s
;
; Ullrich von Bassewitz, 2003-03-07
; 2003-03-07, Ullrich von Bassewitz,
; based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2005-02-26, Ullrich von Bassewitz
; 2014-04-02, Greg King
;
; Setup arguments for main
; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument.
; Send, to main(), that array and the count of the arguments.
;
; Command-lines look like these lines:
;
; run
; run : rem
; run:rem arg1 " arg 2 is quoted " arg3 "" arg5
;
; "run" and "rem" are entokenned; the args. are not. Leading and trailing
; spaces outside of quotes are ignored.
;
; TO-DO:
; - The "file-name" might be a path-name; don't copy the directory-components.
; - Add a control-character quoting mechanism.
.constructor initmainargs, 24
.import __argc, __argv
.import sys_bank, restore_bank
.import sysp0:zp, ptr1:zp
.include "cbm610.inc"
.macpack generic
;---------------------------------------------------------------------------
MAXARGS = 10 ; Maximum number of arguments allowed
REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name
; Get possible command-line arguments. Goes into the special INIT segment,
; which may be reused after the startup code is run
; which may be reused after the startup code is run.
;
.segment "INIT"
.proc initmainargs
initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD
; statement. Save the "most-recent filename" as argument #0.
; Because the buffer, that we're copying into, was zeroed out,
; we don't need to add a NUL character.
;
jsr sys_bank
ldy #FNAM
lda (sysp0),y ; Get file-name pointer from system bank
sta ptr1
iny
lda (sysp0),y
sta ptr1+1
iny ; FNAM_BANK
lda (sysp0),y
tax
ldy #FNAM_LEN
lda (sysp0),y
tay
stx IndReg ; Look for name in correct bank
cpy #NAME_LEN + 1
blt L1
ldy #NAME_LEN - 1 ; limit the length
L0: lda (ptr1),y
sta name,y
L1: dey
bpl L0
jsr restore_bank
inc __argc ; argc always is equal to at least 1
; Find a "rem" token.
;
ldx #0
L2: lda BASIC_BUF,x
bze done ; no "rem," no args.
inx
cmp #REM
bne L2
ldy #1 * 2
; Find the next argument.
;
next: lda BASIC_BUF,x
bze done ; End of line reached
inx
cmp #' ' ; Skip leading spaces
beq next ;
; Found start of next argument. We've incremented the pointer in X already, so
; it points to the second character of the argument. That is useful because we
; will check now for a quoted argument; in which case, we will have to skip that
; first character.
;
found: cmp #'"' ; Is the argument quoted?
beq setterm ; Jump if so
dex ; Reset pointer to first argument character
lda #' ' ; A space ends the argument
setterm:sta term ; Set end-of-argument marker
; Now, store a pointer to the argument into the next slot.
;
txa ; Get low byte
add #<BASIC_BUF
sta argv,y ; argv[y]= &arg
lda #>0
adc #>BASIC_BUF
sta argv+1,y
iny
iny
inc __argc ; Found another arg
; Search for the end of the argument.
;
argloop:lda BASIC_BUF,x
bze done
inx
cmp term
bne argloop
; We've found the end of the argument. X points one character behind it, and
; A contains the terminating character. To make the argument a valid C string,
; replace the terminating character by a zero.
;
lda #0
sta BASIC_BUF-1,x
; Check if the maximum number of command-line arguments is reached. If not,
; parse the next one.
;
lda __argc ; Get low byte of argument count
cmp #MAXARGS ; Maximum number of arguments reached?
blt next ; Parse next one if not
; (The last vector in argv[] already is NULL.)
;
done: lda #<argv
ldx #>argv
sta __argv
stx __argv + 1
rts
.endproc
; These arrays are zeroed before initmainargs is called.
; char name[16+1];
; char* argv[MAXARGS+1]={name};
;
.bss
term: .res 1
name: .res NAME_LEN + 1
.data
argv: .addr name
.res MAXARGS * 2, 0

View File

@@ -0,0 +1,23 @@
;
; Oliver Schmidt, 2014-03-27
;
; CC65 library: 8x8 => 16 unsigned multiplication
;
.export _cc65_umul8x8r16
.import umul8x8r16, popa
.include "zeropage.inc"
;---------------------------------------------------------------------------
; 8x8 => 16 unsigned multiplication routine.
.proc _cc65_umul8x8r16
sta ptr1
jsr popa
jmp umul8x8r16
.endproc