Merge remote-tracking branch 'origin/master' into coniopeek

This commit is contained in:
mrdudz
2022-07-24 03:24:45 +02:00
2250 changed files with 195541 additions and 36938 deletions

View File

@@ -6,7 +6,6 @@
.export screensize
.import SCREEN
screensize = SCREEN

View File

@@ -1,7 +1,7 @@
;
; Ullrich von Bassewitz, 27.09.1998
;
; void set_brk (unsigned Addr);
; void __fastcall__ set_brk (unsigned Addr);
; void reset_brk (void);
;

45
libsrc/cbm610/cpeekc.s Normal file
View File

@@ -0,0 +1,45 @@
;
; 2016-02-28, Groepaz
; 2017-06-19, Greg King
;
; char cpeekc (void);
;
.export _cpeekc
.import CURS_X: zp, CharPtr: zp
.include "cbm610.inc"
_cpeekc:
ldx IndReg
ldy #$0F
sty IndReg
ldy CURS_X
lda (CharPtr),y ; get char from system bank
stx IndReg
ldx #>$0000
and #<~$80 ; remove reverse bit
; Convert the screen code into a PetSCII code.
; $00 - $1F: +$40
; $20 - $3F
; $40 - $5f: +$20
; $60 - $7F: +$40
cmp #$20
bcs @sk1 ;(bge)
ora #$40
rts
@sk1: cmp #$40
bcc @end ;(blt)
cmp #$60
bcc @sk2 ;(blt)
;sec
adc #$20 - $01
@sk2: ;clc ; both above cmp and adc clear carry flag
adc #$20
@end: rts

View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,29 @@
;
; 2016-02-28, Groepaz
; 2017-06-19, Greg King
;
; unsigned char cpeekrevers (void);
;
.export _cpeekrevers
.import plot
.import CURS_X: zp, CharPtr: zp
.include "cbm610.inc"
_cpeekrevers:
ldx IndReg
ldy #$0F
sty IndReg
ldy CURS_X
lda (CharPtr),y ; get char from system bank
stx IndReg
ldx #>$0000
and #$80 ; get reverse bit
asl a
tax ; ldx #>$0000
rol a ; return boolean value
rts

82
libsrc/cbm610/cpeeks.s Normal file
View File

@@ -0,0 +1,82 @@
;
; 2017-07-05, Greg King
;
; void cpeeks (char* s, unsigned length);
;
.export _cpeeks
.import popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.importzp CURS_X, CharPtr
.include "cbm610.inc"
.macpack generic
_cpeeks:
eor #<$FFFF ; counting a word upward is faster
sta ptr3 ; so, we use -(length + 1)
txa
eor #>$FFFF
sta ptr3+1
lda CharPtr
ldx CharPtr+1
sta ptr2
stx ptr2+1
ldy CURS_X
sty tmp2
jsr popax
sta tmp1 ; (will be a .Y index)
stx ptr1+1
ldx IndReg
ldy #<$0000
sty ptr1
bze L3 ; branch always
L4: ldy #$0F
sty IndReg
ldy tmp2
lda (ptr2),y ; get char from system bank
stx IndReg
iny
bnz L2
inc ptr2+1
L2: sty tmp2
and #<~$80 ; remove reverse bit
; Convert the screen code into a PetSCII code.
; $00 - $1F: +$40
; $20 - $3F
; $40 - $5f: +$20
; $60 - $7F: +$40
cmp #$20
blt @sk1 ;(bcc)
cmp #$40
blt L5
cmp #$60
blt @sk2 ;(bcc)
clc
@sk1: adc #$20
@sk2: ;clc ; both above cmp and adc clear carry flag
adc #$20
L5: ldy tmp1
sta (ptr1),y
iny
bnz L1
inc ptr1+1
L1: sty tmp1
L3: inc ptr3 ; count length
bnz L4
inc ptr3+1
bnz L4
lda #$00 ; terminate the string
ldy tmp1
sta (ptr1),y
rts

View File

@@ -9,8 +9,7 @@
.export newline, plot
.destructor setsyscursor
.import _gotoxy
.import popa
.import gotoxy
.import PLOT
.import ktmp: zp, crtc: zp, CURS_X: zp, CURS_Y: zp, RVS: zp
@@ -21,8 +20,7 @@
_cputcxy:
pha ; Save C
jsr popa ; Get Y
jsr _gotoxy ; Set cursor, drop x
jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C
; Plot a character - also used as internal function
@@ -75,10 +73,9 @@ L4: inc CURS_Y
; Handle character if high bit set
L10: and #$7F
cmp #$7E ; PI?
cmp #$7F ; PI?
bne L11
lda #$5E ; Load screen code for PI
bne cputdirect
L11: ora #$40
bne cputdirect ; Branch always

View File

@@ -1,43 +1,45 @@
;
; Stefan Haubenthal, 2009-07-27
; Ullrich von Bassewitz, 2009-09-24
; 2009-07-27, Stefan Haubenthal
; 2009-09-24, Ullrich von Bassewitz
; 2018-08-18, Oliver Schmidt
; 2018-08-19, Greg King
;
; time_t _systime (void);
; /* Similar to time(), but:
; ** - Is not ISO C
; ** - Does not take the additional pointer
; ** - Does not set errno when returning -1
; */
; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
;
.include "time.inc"
.include "cbm610.inc"
.include "extzp.inc"
.import pushax, pusheax, tosmul0ax, steaxspidx, incsp1
.import sys_bank, restore_bank
.importzp tmp1, tmp2
.import TM, load_tenth
.importzp sreg, tmp1, tmp2
;----------------------------------------------------------------------------
.code
.proc __systime
.proc _clock_gettime
; Switch to the system bank
jsr pushax
jsr pushax
jsr sys_bank
; Read the clock
ldy #CIA::TODHR
lda (cia),y
bpl AM
and #%01111111
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
cld
AM: jsr BCD2dec
@L2: cld
jsr BCD2dec
sta TM + tm::tm_hour
ldy #CIA::TODMIN
lda (cia),y
@@ -48,17 +50,28 @@ AM: jsr BCD2dec
jsr BCD2dec
sta TM + tm::tm_sec
ldy #CIA::TOD10
lda (cia),y ; Dummy read to unfreeze
; Restore the bank
lda (cia),y
jsr restore_bank
; Convert to a time
pha
lda #<TM
ldx #>TM
jmp _mktime
jsr _mktime
ldy #timespec::tv_sec
jsr steaxspidx ; Pops address pushed by 2. pushax
jsr load_tenth
jsr pusheax
pla
ldx #>$0000
jsr tosmul0ax
ldy #timespec::tv_nsec
jsr steaxspidx ; Pops address pushed by 1. pushax
lda #$00
tax
jmp incsp1
.endproc
@@ -81,18 +94,3 @@ AM: jsr BCD2dec
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

View File

@@ -4,9 +4,10 @@
; CBM610 kernal functions
;
.include "cbm_kernal.inc"
.export CINT
.export IOINIT
.export RAMTAS
.export RESTOR
.export VECTOR
.export SETMSG
@@ -27,57 +28,12 @@
.export CKOUT
.export CLRCH
.export BASIN
.export CHRIN
.export BSOUT
.export CHROUT
.export LOAD
.export SAVE
.export STOP
.export GETIN
.export CLALL
.export PLOT
;-----------------------------------------------------------------------------
; All functions are available in the kernal jump table. Functions having
; replacements (usually short ones where the overhead of the cross bank call
; is not worth the trouble) are commented out.
CINT = $FF81
IOINIT = $FF84
RAMTAS = $FF87
RESTOR = $FF8A
VECTOR = $FF8D
SETMSG = $FF90
SECOND = $FF93
TKSA = $FF96
MEMTOP = $FF99
MEMBOT = $FF9C
SCNKEY = $FF9F
SETTMO = $FFA2
ACPTR = $FFA5
CIOUT = $FFA8
UNTLK = $FFAB
UNLSN = $FFAE
LISTEN = $FFB1
TALK = $FFB4
;READST = $FFB7
SETLFS = $FFBA
;SETNAM = $FFBD
;OPEN = $FFC0
;CLOSE = $FFC3
CHKIN = $FFC6
CKOUT = $FFC9
CLRCH = $FFCC
BASIN = $FFCF
BSOUT = $FFD2
LOAD = $FFD5
SAVE = $FFD8
;SETTIM = $FFDB
;RDTIM = $FFDE
STOP = $FFE1
GETIN = $FFE4
CLALL = $FFE7
;UDTIM = $FFEA
;SCREEN = $FFED
PLOT = $FFF0
;IOBASE = $FFF3

View File

@@ -3,10 +3,10 @@
;
; OPEN kernal call.
;
; NOTE: The OPEN system call in the CBM610 kernal is different from the
; NOTE: The OPEN system call in the CBM610 kernal is different from the
; standard. It evaluates the carry flag and does a normal open if carry clear
; and some strange things (output sa 15 + name on IEC) if carry set. To be
; compatible with our CBM file stuff, we have to clear the carry before
; compatible with our CBM file stuff, we have to clear the carry before
; calling the real OPEN.
.export OPEN
@@ -18,5 +18,3 @@
.endproc

View File

@@ -12,7 +12,7 @@
.import sys_bank, restore_bank
.import sysp0: zp, ktmp: zp
.include "cbm610.inc"
.proc SETNAM
@@ -41,5 +41,3 @@
.endproc

View File

@@ -3,7 +3,7 @@
;
; udtim routine for the 610. We will not check for the stop key here, since
; C programs will not use it.
;
;
.export UDTIM
.import time: zp

View File

@@ -35,10 +35,10 @@ 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,
; Get possible command-line arguments. Goes into the special ONCE segment,
; which may be reused after the startup code is run.
;
.segment "INIT"
.segment "ONCE"
initmainargs:
@@ -142,7 +142,7 @@ done: lda #<argv
stx __argv + 1
rts
.segment "INITBSS"
.segment "INIT"
term: .res 1
name: .res NAME_LEN + 1

View File

@@ -10,7 +10,7 @@
.import _srand
.importzp time
__randomize:
__randomize:
ldx time+2 ; Use 50/60HZ clock
lda time+1
jmp _srand ; Initialize generator

View File

@@ -9,7 +9,7 @@
.import RVS: zp
.include "cbm610.inc"
.proc _revers

View File

@@ -46,15 +46,15 @@
; Jump table
.word INSTALL
.word UNINSTALL
.word OPEN
.word CLOSE
.word GET
.word PUT
.word STATUS
.word IOCTL
.word IRQ
.word SER_INSTALL
.word SER_UNINSTALL
.word SER_OPEN
.word SER_CLOSE
.word SER_GET
.word SER_PUT
.word SER_STATUS
.word SER_IOCTL
.word SER_IRQ
;----------------------------------------------------------------------------
;
@@ -122,25 +122,25 @@ ParityTable:
.code
;----------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
; SER_INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present.
; Must return an SER_ERR_xx code in a/x.
;
; Since we don't have to manage the IRQ vector on the Plus/4, this is actually
; the same as:
;
; UNINSTALL routine. Is called before the driver is removed from memory.
; SER_UNINSTALL routine. Is called before the driver is removed from memory.
; Must return an SER_ERR_xx code in a/x.
;
; and:
;
; CLOSE: Close the port, disable interrupts and flush the buffer. Called
; SER_CLOSE: Close the port, disable interrupts and flush the buffer. Called
; without parameters. Must return an error code in a/x.
;
INSTALL:
UNINSTALL:
CLOSE:
SER_INSTALL:
SER_UNINSTALL:
SER_CLOSE:
; Deactivate DTR and disable 6551 interrupts
@@ -157,7 +157,7 @@ CLOSE:
; PARAMS routine. A pointer to a ser_params structure is passed in ptr1.
; Must return an SER_ERR_xx code in a/x.
OPEN:
SER_OPEN:
; Check if the handshake setting is valid
@@ -237,12 +237,13 @@ InvBaud:
rts
;----------------------------------------------------------------------------
; GET: Will fetch a character from the receive buffer and store it into the
; SER_GET: Will fetch a character from the receive buffer and store it into the
; variable pointer to by ptr1. If no data is available, SER_ERR_NO_DATA is
; return.
;
GET: ldx SendFreeCnt ; Send data if necessary
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
@@ -281,11 +282,11 @@ GET: ldx SendFreeCnt ; Send data if necessary
rts
;----------------------------------------------------------------------------
; PUT: Output character in A.
; SER_PUT: Output character in A.
; Must return an error code in a/x.
;
PUT:
SER_PUT:
; Try to send
@@ -315,11 +316,12 @@ 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 error code in a/x.
;
STATUS: lda #$0F
SER_STATUS:
lda #$0F
sta IndReg
ldy #ACIA::STATUS
lda (acia),y
@@ -331,23 +333,25 @@ STATUS: lda #$0F
rts
;----------------------------------------------------------------------------
; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
; SER_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 a/x.
;
IOCTL: lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now
SER_IOCTL:
lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now
ldx #>SER_ERR_INV_IOCTL
rts
;----------------------------------------------------------------------------
; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
; SER_IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
; registers are already save, 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: lda #$0F
SER_IRQ:
lda #$0F
sta IndReg ; Switch to the system bank
ldy #ACIA::STATUS
lda (acia),y ; Check ACIA status for receive interrupt
@@ -436,4 +440,3 @@ write: pha
lda ExecReg
sta IndReg
rts

97
libsrc/cbm610/settime.s Normal file
View File

@@ -0,0 +1,97 @@
;
; 2018-08-18, Oliver Schmidt
; 2018-08-19, Greg King
;
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
;
.include "time.inc"
.include "cbm610.inc"
.include "extzp.inc"
.importzp sreg, ptr1
.import pushax, pusheax, ldax0sp, ldeaxidx
.import sys_bank, restore_bank
.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
jsr sys_bank
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: ldy #CIA::TODHR
sta (cia),y
lda TM + tm::tm_min
jsr dec2BCD
ldy #CIA::TODMIN
sta (cia),y
lda TM + tm::tm_sec
jsr dec2BCD
ldy #CIA::TODSEC
sta (cia),y
jsr restore_bank
jsr ldax0sp
ldy #3+timespec::tv_nsec
jsr ldeaxidx
jsr pusheax
jsr load_tenth
jsr tosdiveax
jsr sys_bank
ldy #CIA::TOD10
sta (cia),y
jsr restore_bank
lda #$00
tax
jmp incsp3
.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

41
libsrc/cbm610/tmcommon.s Normal file
View File

@@ -0,0 +1,41 @@
;
; Oliver Schmidt, 16.8.2018
;
; Common stuff for the clock routines
;
.include "cbm610.inc"
.export TM, load_tenth
.importzp sreg
;----------------------------------------------------------------------------
.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
;----------------------------------------------------------------------------
; 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