Add KIM-1 Support
This commit is contained in:
47
libsrc/kim1/crt0.s
Normal file
47
libsrc/kim1/crt0.s
Normal file
@@ -0,0 +1,47 @@
|
||||
;
|
||||
; Startup code for cc65 (kim-1 version)
|
||||
;
|
||||
|
||||
.export _init, _exit
|
||||
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
||||
|
||||
.import _main
|
||||
.import initlib, donelib, copydata, zerobss
|
||||
.import __RAM_START__, __RAM_SIZE__ ; Linker generated
|
||||
.import __STACKSIZE__ ; Linker generated
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "kim1.inc"
|
||||
|
||||
|
||||
; Place the startup code in a special segment
|
||||
|
||||
.segment "STARTUP"
|
||||
|
||||
|
||||
; A little light housekeeping
|
||||
|
||||
_init: cld ; Clear decimal mode
|
||||
|
||||
; Set cc65 argument stack pointer
|
||||
|
||||
lda #<(__RAM_START__ + __RAM_SIZE__)
|
||||
sta sp
|
||||
lda #>(__RAM_START__ + __RAM_SIZE__)
|
||||
sta sp+1
|
||||
|
||||
; Initialize memory storage
|
||||
|
||||
jsr zerobss ; Clear BSS segment
|
||||
jsr copydata ; Initialize DATA segment
|
||||
jsr initlib ; Run constructors
|
||||
|
||||
; Call main()
|
||||
|
||||
jsr _main
|
||||
|
||||
; Back from main (this is also the _exit entry). There may be a more elegant way to9
|
||||
; return to the monitor on the Kim-1, but I don't know it!
|
||||
|
||||
_exit: brk
|
||||
|
||||
5
libsrc/kim1/ctype.s
Normal file
5
libsrc/kim1/ctype.s
Normal file
@@ -0,0 +1,5 @@
|
||||
; Character specification table.
|
||||
;
|
||||
; uses the "common" definition
|
||||
|
||||
.include "ctype_common.inc"
|
||||
51
libsrc/kim1/read.s
Normal file
51
libsrc/kim1/read.s
Normal file
@@ -0,0 +1,51 @@
|
||||
;
|
||||
; int __fastcall__ read (int fd, void* buf, unsigned count);
|
||||
;
|
||||
|
||||
.include "kim1.inc"
|
||||
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3
|
||||
|
||||
.export _read
|
||||
|
||||
.proc _read
|
||||
|
||||
sta ptr3
|
||||
stx ptr3+1 ; Count in ptr3
|
||||
inx
|
||||
stx ptr2+1 ; Increment and store in ptr2
|
||||
tax
|
||||
inx
|
||||
stx ptr2
|
||||
jsr popptr1 ; Buffer address in ptr1
|
||||
jsr popax
|
||||
|
||||
begin: dec ptr2
|
||||
bne getch
|
||||
dec ptr2+1
|
||||
beq done ; If buffer full, return
|
||||
|
||||
getch: jsr INTCHR ; Get character using Monitor ROM call
|
||||
;jsr OUTCHR ; Echo it
|
||||
and #$7F ; Clear top bit
|
||||
cmp #$07 ; Check for '\a'
|
||||
bne chkcr ; ...if BEL character
|
||||
;jsr BEEP ; Make beep sound TODO
|
||||
chkcr: cmp #$0D ; Check for '\r'
|
||||
bne putch ; ...if CR character
|
||||
lda #$0A ; Replace with '\n'
|
||||
jsr OUTCHR ; and echo it
|
||||
|
||||
putch: ldy #$00 ; Put char into return buffer
|
||||
sta (ptr1),y
|
||||
inc ptr1 ; Increment pointer
|
||||
bne begin
|
||||
inc ptr1+1
|
||||
bne begin
|
||||
|
||||
done: lda ptr3
|
||||
ldx ptr3+1
|
||||
rts ; Return count
|
||||
|
||||
.endproc
|
||||
39
libsrc/kim1/tapeio.s
Normal file
39
libsrc/kim1/tapeio.s
Normal file
@@ -0,0 +1,39 @@
|
||||
;
|
||||
; int __fastcall__ loadt (unsigned char id);
|
||||
; int __fastcall__ dumpt (unsigned char id, void* start_addr, void* end_addr);
|
||||
;
|
||||
|
||||
.include "kim1.inc"
|
||||
|
||||
.import popa, popax, return0, return1
|
||||
|
||||
.export _loadt, _dumpt
|
||||
|
||||
.segment "CODE"
|
||||
|
||||
.proc _loadt: near
|
||||
|
||||
sta ID ; Tape record ID to P1L
|
||||
jsr LOADT ; Read data from tape
|
||||
bcs error
|
||||
jmp return0 ; Return 0 if sucessful
|
||||
error: jmp return1 ; or 1 if not
|
||||
|
||||
.endproc
|
||||
|
||||
.proc _dumpt: near
|
||||
|
||||
sta EAL ; End address
|
||||
stx EAH
|
||||
jsr popax
|
||||
sta SAL ; Start address
|
||||
stx SAH
|
||||
jsr popa
|
||||
sta ID ; Tape Record ID
|
||||
ldx #$00
|
||||
jsr DUMPT ; Write data to tape
|
||||
bcs error
|
||||
jmp return0 ; Return 0 if sucessful
|
||||
error: jmp return1 ; or 1 if not
|
||||
|
||||
.endproc
|
||||
49
libsrc/kim1/write.s
Normal file
49
libsrc/kim1/write.s
Normal file
@@ -0,0 +1,49 @@
|
||||
;
|
||||
; int __fastcall__ write (int fd, const void* buf, int count);
|
||||
;
|
||||
|
||||
.include "kim1.inc"
|
||||
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3
|
||||
|
||||
.export _write
|
||||
|
||||
.proc _write
|
||||
|
||||
sta ptr3
|
||||
stx ptr3+1 ; Count in ptr3
|
||||
inx
|
||||
stx ptr2+1 ; Increment and store in ptr2
|
||||
tax
|
||||
inx
|
||||
stx ptr2
|
||||
jsr popptr1 ; Buffer address in ptr1
|
||||
jsr popax
|
||||
|
||||
begin: dec ptr2
|
||||
bne outch
|
||||
dec ptr2+1
|
||||
beq done
|
||||
|
||||
outch: ldy #0
|
||||
lda (ptr1),y
|
||||
jsr OUTCHR ; Send character using Monitor call
|
||||
cmp #$07 ; Check for '\a'
|
||||
bne chklf ; ...if BEL character
|
||||
;jsr BEEP ; Make beep sound
|
||||
chklf: cmp #$0A ; Check for 'n'
|
||||
bne next ; ...if LF character
|
||||
lda #$0D ; Add a carriage return
|
||||
jsr OUTCHR
|
||||
|
||||
next: inc ptr1
|
||||
bne begin
|
||||
inc ptr1+1
|
||||
jmp begin
|
||||
|
||||
done: lda ptr3
|
||||
ldx ptr3+1
|
||||
rts ; Return count
|
||||
|
||||
.endproc
|
||||
Reference in New Issue
Block a user