some more simple fixes, make targettest(s) work
This commit is contained in:
@@ -105,7 +105,6 @@ L1: lda c_sp,x
|
|||||||
|
|
||||||
; Switch to the second charset.
|
; Switch to the second charset.
|
||||||
|
|
||||||
; FIXME
|
|
||||||
lda #14
|
lda #14
|
||||||
jsr BSOUT
|
jsr BSOUT
|
||||||
|
|
||||||
|
|||||||
25
libsrc/c65/get_tv.s
Normal file
25
libsrc/c65/get_tv.s
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2002-12-03
|
||||||
|
;
|
||||||
|
; unsigned char get_tv (void);
|
||||||
|
; /* Return the video mode the machine is using */
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "get_tv.inc"
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
|
||||||
|
;--------------------------------------------------------------------------
|
||||||
|
; _get_tv
|
||||||
|
|
||||||
|
.proc _get_tv
|
||||||
|
|
||||||
|
ldx #TV::PAL ; Assume PAL
|
||||||
|
lda PALFLAG
|
||||||
|
bne pal
|
||||||
|
dex ; NTSC
|
||||||
|
pal: txa
|
||||||
|
ldx #0
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
83
libsrc/c65/gettime.s
Normal file
83
libsrc/c65/gettime.s
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
;
|
||||||
|
; Stefan Haubenthal, 27.7.2009
|
||||||
|
; Oliver Schmidt, 14.8.2018
|
||||||
|
;
|
||||||
|
; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "time.inc"
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
.importzp sreg, tmp1, tmp2
|
||||||
|
.import pushax, pusheax, tosmul0ax, steaxspidx, incsp1, return0
|
||||||
|
.import TM, load_tenth
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc _clock_gettime
|
||||||
|
|
||||||
|
jsr pushax
|
||||||
|
jsr pushax
|
||||||
|
|
||||||
|
lda CIA1_TODHR
|
||||||
|
sed
|
||||||
|
tax ; Save PM flag
|
||||||
|
and #%01111111
|
||||||
|
cmp #$12 ; 12 AM/PM
|
||||||
|
bcc @L1
|
||||||
|
sbc #$12
|
||||||
|
@L1: inx ; Get PM flag
|
||||||
|
bpl @L2
|
||||||
|
clc
|
||||||
|
adc #$12
|
||||||
|
@L2: cld
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_hour
|
||||||
|
lda CIA1_TODMIN
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_min
|
||||||
|
lda CIA1_TODSEC
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_sec
|
||||||
|
lda #<TM
|
||||||
|
ldx #>TM
|
||||||
|
jsr _mktime
|
||||||
|
|
||||||
|
ldy #timespec::tv_sec
|
||||||
|
jsr steaxspidx ; Pops address pushed by 2. pushax
|
||||||
|
|
||||||
|
jsr load_tenth
|
||||||
|
jsr pusheax
|
||||||
|
lda CIA1_TOD10
|
||||||
|
ldx #>$0000
|
||||||
|
jsr tosmul0ax
|
||||||
|
|
||||||
|
ldy #timespec::tv_nsec
|
||||||
|
jsr steaxspidx ; Pops address pushed by 1. pushax
|
||||||
|
|
||||||
|
jsr incsp1
|
||||||
|
jmp return0
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; dec = (((BCD>>4)*10) + (BCD&0xf))
|
||||||
|
|
||||||
|
.proc BCD2dec
|
||||||
|
|
||||||
|
tax
|
||||||
|
and #%00001111
|
||||||
|
sta tmp1
|
||||||
|
txa
|
||||||
|
and #%11110000 ; *16
|
||||||
|
lsr ; *8
|
||||||
|
sta tmp2
|
||||||
|
lsr
|
||||||
|
lsr ; *2
|
||||||
|
adc tmp2 ; = *10
|
||||||
|
adc tmp1
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
137
libsrc/c65/mainargs.s
Normal file
137
libsrc/c65/mainargs.s
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
; mainargs.s
|
||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2003-03-07
|
||||||
|
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
|
||||||
|
; 2003-05-18, Greg King
|
||||||
|
; 2004-04-28, 2005-02-26, Ullrich von Bassewitz
|
||||||
|
;
|
||||||
|
; 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
|
||||||
|
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
|
||||||
|
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 ONCE segment,
|
||||||
|
; which may be reused after the startup code is run
|
||||||
|
|
||||||
|
.segment "ONCE"
|
||||||
|
|
||||||
|
initmainargs:
|
||||||
|
|
||||||
|
; Assume that the program was loaded, a moment ago, by the traditional LOAD
|
||||||
|
; statement. Save the "most-recent filename" as argument #0.
|
||||||
|
|
||||||
|
lda #0 ; The terminating NUL character
|
||||||
|
ldy FNAM_LEN
|
||||||
|
cpy #NAME_LEN + 1
|
||||||
|
bcc L1
|
||||||
|
ldy #NAME_LEN ; Limit the length
|
||||||
|
bne L1 ; Branch always
|
||||||
|
L0: lda (FNAM),y
|
||||||
|
L1: sta name,y
|
||||||
|
dey
|
||||||
|
bpl L0
|
||||||
|
inc __argc ; argc always is equal to, at least, 1
|
||||||
|
|
||||||
|
; Find the "rem" token.
|
||||||
|
|
||||||
|
ldx #0
|
||||||
|
L2: lda BASIC_BUF,x
|
||||||
|
beq done ; No "rem," no args.
|
||||||
|
inx
|
||||||
|
cmp #REM
|
||||||
|
bne L2
|
||||||
|
ldy #1 * 2
|
||||||
|
|
||||||
|
; Find the next argument
|
||||||
|
|
||||||
|
next: lda BASIC_BUF,x
|
||||||
|
beq 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. This is useful since we
|
||||||
|
; will check now for a quoted argument, in which case we will have to skip this
|
||||||
|
; 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. Since the BASIC
|
||||||
|
; input buffer is located at the start of a RAM page, no calculations are
|
||||||
|
; necessary.
|
||||||
|
|
||||||
|
txa ; Get low byte
|
||||||
|
sta argv,y ; argv[y]= &arg
|
||||||
|
iny
|
||||||
|
lda #>BASIC_BUF
|
||||||
|
sta argv,y
|
||||||
|
iny
|
||||||
|
inc __argc ; Found another arg
|
||||||
|
|
||||||
|
; Search for the end of the argument
|
||||||
|
|
||||||
|
argloop:lda BASIC_BUF,x
|
||||||
|
beq 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?
|
||||||
|
bcc 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
|
||||||
|
|
||||||
|
.segment "INIT"
|
||||||
|
|
||||||
|
term: .res 1
|
||||||
|
name: .res NAME_LEN + 1
|
||||||
|
|
||||||
|
.data
|
||||||
|
|
||||||
|
; char* argv[MAXARGS+1]={name};
|
||||||
|
argv: .addr name
|
||||||
|
.res MAXARGS * 2
|
||||||
18
libsrc/c65/randomize.s
Normal file
18
libsrc/c65/randomize.s
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
;
|
||||||
|
; 2002-11-05, Ullrich von Bassewitz
|
||||||
|
; 2015-09-11, Greg King
|
||||||
|
;
|
||||||
|
; void __randomize (void);
|
||||||
|
; /* Initialize the random number generator */
|
||||||
|
;
|
||||||
|
|
||||||
|
.export ___randomize
|
||||||
|
.import _srand
|
||||||
|
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
___randomize:
|
||||||
|
ldx VIC_HLINE ; Use VIC rasterline as high byte
|
||||||
|
lda TIME+2 ; Use 60HZ clock as low byte
|
||||||
|
jmp _srand ; Initialize generator
|
||||||
|
|
||||||
27
libsrc/c65/revers.s
Normal file
27
libsrc/c65/revers.s
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 07.08.1998
|
||||||
|
;
|
||||||
|
; unsigned char revers (unsigned char onoff);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _revers
|
||||||
|
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
.proc _revers
|
||||||
|
|
||||||
|
ldx #$00 ; Assume revers off
|
||||||
|
tay ; Test onoff
|
||||||
|
beq L1 ; Jump if off
|
||||||
|
ldx #$80 ; Load on value
|
||||||
|
ldy #$00 ; Assume old value is zero
|
||||||
|
L1: lda RVS ; Load old value
|
||||||
|
stx RVS ; Set new value
|
||||||
|
beq L2 ; Jump if old value zero
|
||||||
|
iny ; Make old value = 1
|
||||||
|
L2: ldx #$00 ; Load high byte of result
|
||||||
|
tya ; Load low byte, set CC
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
84
libsrc/c65/settime.s
Normal file
84
libsrc/c65/settime.s
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
;
|
||||||
|
; Oliver Schmidt, 16.8.2018
|
||||||
|
;
|
||||||
|
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "time.inc"
|
||||||
|
.include "c65.inc"
|
||||||
|
|
||||||
|
.importzp sreg, ptr1
|
||||||
|
.import pushax, pusheax, ldax0sp, ldeaxidx
|
||||||
|
.import tosdiveax, incsp3, return0
|
||||||
|
.import TM, load_tenth
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc _clock_settime
|
||||||
|
|
||||||
|
jsr pushax
|
||||||
|
|
||||||
|
.assert timespec::tv_sec = 0, error
|
||||||
|
jsr _localtime
|
||||||
|
sta ptr1
|
||||||
|
stx ptr1+1
|
||||||
|
ldy #.sizeof(tm)-1
|
||||||
|
@L1: lda (ptr1),y
|
||||||
|
sta TM,y
|
||||||
|
dey
|
||||||
|
bpl @L1
|
||||||
|
|
||||||
|
lda TM + tm::tm_hour
|
||||||
|
jsr dec2BCD
|
||||||
|
tax ; Force flags
|
||||||
|
bne @L2
|
||||||
|
lda #$92 ; 12 AM
|
||||||
|
bne @L3
|
||||||
|
@L2: cmp #$13 ; 1 PM
|
||||||
|
bcc @L3
|
||||||
|
sed
|
||||||
|
sbc #$12
|
||||||
|
cld
|
||||||
|
ora #%10000000
|
||||||
|
@L3: sta CIA1_TODHR
|
||||||
|
lda TM + tm::tm_min
|
||||||
|
jsr dec2BCD
|
||||||
|
sta CIA1_TODMIN
|
||||||
|
lda TM + tm::tm_sec
|
||||||
|
jsr dec2BCD
|
||||||
|
sta CIA1_TODSEC
|
||||||
|
|
||||||
|
jsr ldax0sp
|
||||||
|
ldy #3+timespec::tv_nsec
|
||||||
|
jsr ldeaxidx
|
||||||
|
jsr pusheax
|
||||||
|
jsr load_tenth
|
||||||
|
jsr tosdiveax
|
||||||
|
sta CIA1_TOD10
|
||||||
|
|
||||||
|
jsr incsp3
|
||||||
|
jmp return0
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; Just sum up the value in BCD mode.
|
||||||
|
; http://forum.6502.org/viewtopic.php?p=7629#p7629
|
||||||
|
|
||||||
|
.proc dec2BCD
|
||||||
|
|
||||||
|
tax
|
||||||
|
dex
|
||||||
|
bmi @L9
|
||||||
|
lda #0
|
||||||
|
clc
|
||||||
|
sed
|
||||||
|
@L1: adc #1
|
||||||
|
dex
|
||||||
|
bpl @L1
|
||||||
|
cld
|
||||||
|
@L9: rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
37
libsrc/c65/sysuname.s
Normal file
37
libsrc/c65/sysuname.s
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2003-08-12
|
||||||
|
;
|
||||||
|
; unsigned char __fastcall__ _sysuname (struct utsname* buf);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export __sysuname, utsdata
|
||||||
|
|
||||||
|
.import utscopy
|
||||||
|
|
||||||
|
__sysuname = utscopy
|
||||||
|
|
||||||
|
;--------------------------------------------------------------------------
|
||||||
|
; Data. We define a fixed utsname struct here and just copy it.
|
||||||
|
|
||||||
|
.rodata
|
||||||
|
|
||||||
|
utsdata:
|
||||||
|
; sysname
|
||||||
|
.asciiz "cc65"
|
||||||
|
|
||||||
|
; nodename
|
||||||
|
.asciiz ""
|
||||||
|
|
||||||
|
; release
|
||||||
|
.byte .string (>.version)
|
||||||
|
.byte '.'
|
||||||
|
.byte .string (<.version)
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
; version
|
||||||
|
.byte '0' ; unused
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
; machine
|
||||||
|
.asciiz "Commodore 65"
|
||||||
|
|
||||||
64
libsrc/c65/tmcommon.s
Normal file
64
libsrc/c65/tmcommon.s
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
;
|
||||||
|
; Oliver Schmidt, 16.8.2018
|
||||||
|
;
|
||||||
|
; Common stuff for the clock routines
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "c65.inc"
|
||||||
|
.include "get_tv.inc"
|
||||||
|
|
||||||
|
.export TM, load_tenth
|
||||||
|
|
||||||
|
.constructor inittime
|
||||||
|
.importzp sreg
|
||||||
|
.import _get_tv
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc load_tenth
|
||||||
|
|
||||||
|
lda #<(100 * 1000 * 1000 / $10000)
|
||||||
|
ldx #>(100 * 1000 * 1000 / $10000)
|
||||||
|
sta sreg
|
||||||
|
stx sreg+1
|
||||||
|
lda #<(100 * 1000 * 1000)
|
||||||
|
ldx #>(100 * 1000 * 1000)
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; Constructor that writes to the 1/10 sec register of the TOD to kick it
|
||||||
|
; into action. If this is not done, the clock hangs. We will read the register
|
||||||
|
; and write it again, ignoring a possible change in between.
|
||||||
|
.segment "ONCE"
|
||||||
|
|
||||||
|
.proc inittime
|
||||||
|
|
||||||
|
lda CIA1_TOD10
|
||||||
|
sta CIA1_TOD10
|
||||||
|
jsr _get_tv
|
||||||
|
cmp #TV::PAL
|
||||||
|
bne @60Hz
|
||||||
|
lda CIA1_CRA
|
||||||
|
ora #$80
|
||||||
|
sta CIA1_CRA
|
||||||
|
@60Hz: rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; TM struct with date set to 1970-01-01
|
||||||
|
.data
|
||||||
|
|
||||||
|
TM: .word 0 ; tm_sec
|
||||||
|
.word 0 ; tm_min
|
||||||
|
.word 0 ; tm_hour
|
||||||
|
.word 1 ; tm_mday
|
||||||
|
.word 0 ; tm_mon
|
||||||
|
.word 70 ; tm_year
|
||||||
|
.word 0 ; tm_wday
|
||||||
|
.word 0 ; tm_yday
|
||||||
|
.word 0 ; tm_isdst
|
||||||
@@ -105,7 +105,6 @@ L1: lda c_sp,x
|
|||||||
|
|
||||||
; Switch to the second charset.
|
; Switch to the second charset.
|
||||||
|
|
||||||
; FIXME
|
|
||||||
lda #14
|
lda #14
|
||||||
jsr BSOUT
|
jsr BSOUT
|
||||||
|
|
||||||
|
|||||||
25
libsrc/mega65/get_tv.s
Normal file
25
libsrc/mega65/get_tv.s
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2002-12-03
|
||||||
|
;
|
||||||
|
; unsigned char get_tv (void);
|
||||||
|
; /* Return the video mode the machine is using */
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "get_tv.inc"
|
||||||
|
.include "mega65.inc"
|
||||||
|
|
||||||
|
|
||||||
|
;--------------------------------------------------------------------------
|
||||||
|
; _get_tv
|
||||||
|
|
||||||
|
.proc _get_tv
|
||||||
|
|
||||||
|
ldx #TV::PAL ; Assume PAL
|
||||||
|
lda PALFLAG
|
||||||
|
bne pal
|
||||||
|
dex ; NTSC
|
||||||
|
pal: txa
|
||||||
|
ldx #0
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
83
libsrc/mega65/gettime.s
Normal file
83
libsrc/mega65/gettime.s
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
;
|
||||||
|
; Stefan Haubenthal, 27.7.2009
|
||||||
|
; Oliver Schmidt, 14.8.2018
|
||||||
|
;
|
||||||
|
; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "time.inc"
|
||||||
|
.include "mega65.inc"
|
||||||
|
|
||||||
|
.importzp sreg, tmp1, tmp2
|
||||||
|
.import pushax, pusheax, tosmul0ax, steaxspidx, incsp1, return0
|
||||||
|
.import TM, load_tenth
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc _clock_gettime
|
||||||
|
|
||||||
|
jsr pushax
|
||||||
|
jsr pushax
|
||||||
|
|
||||||
|
lda CIA1_TODHR
|
||||||
|
sed
|
||||||
|
tax ; Save PM flag
|
||||||
|
and #%01111111
|
||||||
|
cmp #$12 ; 12 AM/PM
|
||||||
|
bcc @L1
|
||||||
|
sbc #$12
|
||||||
|
@L1: inx ; Get PM flag
|
||||||
|
bpl @L2
|
||||||
|
clc
|
||||||
|
adc #$12
|
||||||
|
@L2: cld
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_hour
|
||||||
|
lda CIA1_TODMIN
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_min
|
||||||
|
lda CIA1_TODSEC
|
||||||
|
jsr BCD2dec
|
||||||
|
sta TM + tm::tm_sec
|
||||||
|
lda #<TM
|
||||||
|
ldx #>TM
|
||||||
|
jsr _mktime
|
||||||
|
|
||||||
|
ldy #timespec::tv_sec
|
||||||
|
jsr steaxspidx ; Pops address pushed by 2. pushax
|
||||||
|
|
||||||
|
jsr load_tenth
|
||||||
|
jsr pusheax
|
||||||
|
lda CIA1_TOD10
|
||||||
|
ldx #>$0000
|
||||||
|
jsr tosmul0ax
|
||||||
|
|
||||||
|
ldy #timespec::tv_nsec
|
||||||
|
jsr steaxspidx ; Pops address pushed by 1. pushax
|
||||||
|
|
||||||
|
jsr incsp1
|
||||||
|
jmp return0
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; dec = (((BCD>>4)*10) + (BCD&0xf))
|
||||||
|
|
||||||
|
.proc BCD2dec
|
||||||
|
|
||||||
|
tax
|
||||||
|
and #%00001111
|
||||||
|
sta tmp1
|
||||||
|
txa
|
||||||
|
and #%11110000 ; *16
|
||||||
|
lsr ; *8
|
||||||
|
sta tmp2
|
||||||
|
lsr
|
||||||
|
lsr ; *2
|
||||||
|
adc tmp2 ; = *10
|
||||||
|
adc tmp1
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
137
libsrc/mega65/mainargs.s
Normal file
137
libsrc/mega65/mainargs.s
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
; mainargs.s
|
||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2003-03-07
|
||||||
|
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
|
||||||
|
; 2003-05-18, Greg King
|
||||||
|
; 2004-04-28, 2005-02-26, Ullrich von Bassewitz
|
||||||
|
;
|
||||||
|
; 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
|
||||||
|
|
||||||
|
.include "mega65.inc"
|
||||||
|
|
||||||
|
|
||||||
|
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 ONCE segment,
|
||||||
|
; which may be reused after the startup code is run
|
||||||
|
|
||||||
|
.segment "ONCE"
|
||||||
|
|
||||||
|
initmainargs:
|
||||||
|
|
||||||
|
; Assume that the program was loaded, a moment ago, by the traditional LOAD
|
||||||
|
; statement. Save the "most-recent filename" as argument #0.
|
||||||
|
|
||||||
|
lda #0 ; The terminating NUL character
|
||||||
|
ldy FNAM_LEN
|
||||||
|
cpy #NAME_LEN + 1
|
||||||
|
bcc L1
|
||||||
|
ldy #NAME_LEN ; Limit the length
|
||||||
|
bne L1 ; Branch always
|
||||||
|
L0: lda (FNAM),y
|
||||||
|
L1: sta name,y
|
||||||
|
dey
|
||||||
|
bpl L0
|
||||||
|
inc __argc ; argc always is equal to, at least, 1
|
||||||
|
|
||||||
|
; Find the "rem" token.
|
||||||
|
|
||||||
|
ldx #0
|
||||||
|
L2: lda BASIC_BUF,x
|
||||||
|
beq done ; No "rem," no args.
|
||||||
|
inx
|
||||||
|
cmp #REM
|
||||||
|
bne L2
|
||||||
|
ldy #1 * 2
|
||||||
|
|
||||||
|
; Find the next argument
|
||||||
|
|
||||||
|
next: lda BASIC_BUF,x
|
||||||
|
beq 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. This is useful since we
|
||||||
|
; will check now for a quoted argument, in which case we will have to skip this
|
||||||
|
; 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. Since the BASIC
|
||||||
|
; input buffer is located at the start of a RAM page, no calculations are
|
||||||
|
; necessary.
|
||||||
|
|
||||||
|
txa ; Get low byte
|
||||||
|
sta argv,y ; argv[y]= &arg
|
||||||
|
iny
|
||||||
|
lda #>BASIC_BUF
|
||||||
|
sta argv,y
|
||||||
|
iny
|
||||||
|
inc __argc ; Found another arg
|
||||||
|
|
||||||
|
; Search for the end of the argument
|
||||||
|
|
||||||
|
argloop:lda BASIC_BUF,x
|
||||||
|
beq 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?
|
||||||
|
bcc 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
|
||||||
|
|
||||||
|
.segment "INIT"
|
||||||
|
|
||||||
|
term: .res 1
|
||||||
|
name: .res NAME_LEN + 1
|
||||||
|
|
||||||
|
.data
|
||||||
|
|
||||||
|
; char* argv[MAXARGS+1]={name};
|
||||||
|
argv: .addr name
|
||||||
|
.res MAXARGS * 2
|
||||||
18
libsrc/mega65/randomize.s
Normal file
18
libsrc/mega65/randomize.s
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
;
|
||||||
|
; 2002-11-05, Ullrich von Bassewitz
|
||||||
|
; 2015-09-11, Greg King
|
||||||
|
;
|
||||||
|
; void __randomize (void);
|
||||||
|
; /* Initialize the random number generator */
|
||||||
|
;
|
||||||
|
|
||||||
|
.export ___randomize
|
||||||
|
.import _srand
|
||||||
|
|
||||||
|
.include "mega65.inc"
|
||||||
|
|
||||||
|
___randomize:
|
||||||
|
ldx VIC_HLINE ; Use VIC rasterline as high byte
|
||||||
|
lda TIME+2 ; Use 60HZ clock as low byte
|
||||||
|
jmp _srand ; Initialize generator
|
||||||
|
|
||||||
27
libsrc/mega65/revers.s
Normal file
27
libsrc/mega65/revers.s
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 07.08.1998
|
||||||
|
;
|
||||||
|
; unsigned char revers (unsigned char onoff);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _revers
|
||||||
|
|
||||||
|
.include "mega65.inc"
|
||||||
|
|
||||||
|
.proc _revers
|
||||||
|
|
||||||
|
ldx #$00 ; Assume revers off
|
||||||
|
tay ; Test onoff
|
||||||
|
beq L1 ; Jump if off
|
||||||
|
ldx #$80 ; Load on value
|
||||||
|
ldy #$00 ; Assume old value is zero
|
||||||
|
L1: lda RVS ; Load old value
|
||||||
|
stx RVS ; Set new value
|
||||||
|
beq L2 ; Jump if old value zero
|
||||||
|
iny ; Make old value = 1
|
||||||
|
L2: ldx #$00 ; Load high byte of result
|
||||||
|
tya ; Load low byte, set CC
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
37
libsrc/mega65/sysuname.s
Normal file
37
libsrc/mega65/sysuname.s
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 2003-08-12
|
||||||
|
;
|
||||||
|
; unsigned char __fastcall__ _sysuname (struct utsname* buf);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export __sysuname, utsdata
|
||||||
|
|
||||||
|
.import utscopy
|
||||||
|
|
||||||
|
__sysuname = utscopy
|
||||||
|
|
||||||
|
;--------------------------------------------------------------------------
|
||||||
|
; Data. We define a fixed utsname struct here and just copy it.
|
||||||
|
|
||||||
|
.rodata
|
||||||
|
|
||||||
|
utsdata:
|
||||||
|
; sysname
|
||||||
|
.asciiz "cc65"
|
||||||
|
|
||||||
|
; nodename
|
||||||
|
.asciiz ""
|
||||||
|
|
||||||
|
; release
|
||||||
|
.byte .string (>.version)
|
||||||
|
.byte '.'
|
||||||
|
.byte .string (<.version)
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
; version
|
||||||
|
.byte '0' ; unused
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
; machine
|
||||||
|
.asciiz "MEGA65"
|
||||||
|
|
||||||
64
libsrc/mega65/tmcommon.s
Normal file
64
libsrc/mega65/tmcommon.s
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
;
|
||||||
|
; Oliver Schmidt, 16.8.2018
|
||||||
|
;
|
||||||
|
; Common stuff for the clock routines
|
||||||
|
;
|
||||||
|
|
||||||
|
.include "c65.inc"
|
||||||
|
.include "get_tv.inc"
|
||||||
|
|
||||||
|
.export TM, load_tenth
|
||||||
|
|
||||||
|
.constructor inittime
|
||||||
|
.importzp sreg
|
||||||
|
.import _get_tv
|
||||||
|
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc load_tenth
|
||||||
|
|
||||||
|
lda #<(100 * 1000 * 1000 / $10000)
|
||||||
|
ldx #>(100 * 1000 * 1000 / $10000)
|
||||||
|
sta sreg
|
||||||
|
stx sreg+1
|
||||||
|
lda #<(100 * 1000 * 1000)
|
||||||
|
ldx #>(100 * 1000 * 1000)
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; Constructor that writes to the 1/10 sec register of the TOD to kick it
|
||||||
|
; into action. If this is not done, the clock hangs. We will read the register
|
||||||
|
; and write it again, ignoring a possible change in between.
|
||||||
|
.segment "ONCE"
|
||||||
|
|
||||||
|
.proc inittime
|
||||||
|
|
||||||
|
lda CIA1_TOD10
|
||||||
|
sta CIA1_TOD10
|
||||||
|
jsr _get_tv
|
||||||
|
cmp #TV::PAL
|
||||||
|
bne @60Hz
|
||||||
|
lda CIA1_CRA
|
||||||
|
ora #$80
|
||||||
|
sta CIA1_CRA
|
||||||
|
@60Hz: rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; TM struct with date set to 1970-01-01
|
||||||
|
.data
|
||||||
|
|
||||||
|
TM: .word 0 ; tm_sec
|
||||||
|
.word 0 ; tm_min
|
||||||
|
.word 0 ; tm_hour
|
||||||
|
.word 1 ; tm_mday
|
||||||
|
.word 0 ; tm_mon
|
||||||
|
.word 70 ; tm_year
|
||||||
|
.word 0 ; tm_wday
|
||||||
|
.word 0 ; tm_yday
|
||||||
|
.word 0 ; tm_isdst
|
||||||
@@ -608,6 +608,64 @@ EXELIST_cx16 = \
|
|||||||
strqtok-test \
|
strqtok-test \
|
||||||
uname-test
|
uname-test
|
||||||
|
|
||||||
|
# omitted: deb em-test joy-test mouse-test ser-test seek
|
||||||
|
EXELIST_c65 = \
|
||||||
|
arg-test \
|
||||||
|
clock \
|
||||||
|
clock-test \
|
||||||
|
conio \
|
||||||
|
cpeek-test \
|
||||||
|
cprintf \
|
||||||
|
cursor \
|
||||||
|
dir-test \
|
||||||
|
div-test \
|
||||||
|
exec-test1 \
|
||||||
|
exec-test2 \
|
||||||
|
fileio-test \
|
||||||
|
ft \
|
||||||
|
getopt-test \
|
||||||
|
heaptest \
|
||||||
|
moddiv-test \
|
||||||
|
mul-test \
|
||||||
|
posixio-test \
|
||||||
|
rename-test \
|
||||||
|
scanf-test \
|
||||||
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
|
stroserror-test \
|
||||||
|
strqtok-test \
|
||||||
|
uname-test \
|
||||||
|
minimal
|
||||||
|
|
||||||
|
# omitted: deb em-test joy-test mouse-test ser-test seek
|
||||||
|
EXELIST_mega65 = \
|
||||||
|
arg-test \
|
||||||
|
clock \
|
||||||
|
clock-test \
|
||||||
|
conio \
|
||||||
|
cpeek-test \
|
||||||
|
cprintf \
|
||||||
|
cursor \
|
||||||
|
dir-test \
|
||||||
|
div-test \
|
||||||
|
exec-test1 \
|
||||||
|
exec-test2 \
|
||||||
|
fileio-test \
|
||||||
|
ft \
|
||||||
|
getopt-test \
|
||||||
|
heaptest \
|
||||||
|
moddiv-test \
|
||||||
|
mul-test \
|
||||||
|
posixio-test \
|
||||||
|
rename-test \
|
||||||
|
scanf-test \
|
||||||
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
|
stroserror-test \
|
||||||
|
strqtok-test \
|
||||||
|
uname-test \
|
||||||
|
minimal
|
||||||
|
|
||||||
# omitted: arg-test clock-test clock cpeek-test cprintf cursor deb dir-test div-test
|
# omitted: arg-test clock-test clock cpeek-test cprintf cursor deb dir-test div-test
|
||||||
# em-test exec-test1 exec-test2 fileio-test ft getopt-test heaptest joy-test moddiv-test
|
# em-test exec-test1 exec-test2 fileio-test ft getopt-test heaptest joy-test moddiv-test
|
||||||
# mouse-test mul-test posixio-test rename-test scanf-test seek ser-test strdup-test
|
# mouse-test mul-test posixio-test rename-test scanf-test seek ser-test strdup-test
|
||||||
@@ -756,6 +814,7 @@ TARGETS := \
|
|||||||
c128 \
|
c128 \
|
||||||
c16 \
|
c16 \
|
||||||
c64 \
|
c64 \
|
||||||
|
c65 \
|
||||||
cbm510 \
|
cbm510 \
|
||||||
cbm610 \
|
cbm610 \
|
||||||
creativision \
|
creativision \
|
||||||
@@ -764,6 +823,7 @@ TARGETS := \
|
|||||||
kim1 \
|
kim1 \
|
||||||
lunix \
|
lunix \
|
||||||
lynx \
|
lynx \
|
||||||
|
mega65 \
|
||||||
nes \
|
nes \
|
||||||
osic1p \
|
osic1p \
|
||||||
pce \
|
pce \
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
# define SCREEN_RAM ((unsigned char*)0x8000)
|
# define SCREEN_RAM ((unsigned char*)0x8000)
|
||||||
#elif defined(__VIC20__)
|
#elif defined(__VIC20__)
|
||||||
# define SCREEN_RAM ((unsigned char*)0x1000)
|
# define SCREEN_RAM ((unsigned char*)0x1000)
|
||||||
|
#elif defined(__C65__)
|
||||||
|
# define SCREEN_RAM ((unsigned char*)0x0800)
|
||||||
|
#elif defined(__MEGA65__)
|
||||||
|
# define SCREEN_RAM ((unsigned char*)0x0800)
|
||||||
#else
|
#else
|
||||||
# error This program cannot test that target.
|
# error This program cannot test that target.
|
||||||
# define SCREEN_RAM ((unsigned char*)0)
|
# define SCREEN_RAM ((unsigned char*)0)
|
||||||
|
|||||||
Reference in New Issue
Block a user