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

This commit is contained in:
mrdudz
2015-10-15 15:07:44 +02:00
52 changed files with 396 additions and 331 deletions

View File

@@ -4,12 +4,12 @@
.export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import initlib, donelib
.import zerobss
.import callmain
.import RESTOR, BSOUT, CLRCH
.import __RAM_START__, __RAM_SIZE__ ; Linker generated
.import __STACKSIZE__ ; Linker generated
.import moveinit, zerobss, callmain
.import BSOUT
.import __MAIN_START__, __MAIN_SIZE__ ; Linker generated
.import __STACKSIZE__ ; from configure file
.importzp ST
.include "zeropage.inc"
@@ -23,14 +23,6 @@
Start:
; Save the zero-page locations that we need.
ldx #zpspace-1
L1: lda sp,x
sta zpsave,x
dex
bpl L1
; Switch to the second charset.
lda #14
@@ -39,31 +31,34 @@ L1: lda sp,x
; Switch off the BASIC ROM.
lda $01
pha ; Remember the value
sta mmusave ; Save the memory configuration
and #$F8
ora #$06 ; Enable Kernal+I/O, disable BASIC
sta $01
; Clear the BSS data.
jsr zerobss
; Save some system settings; and, set up the stack.
pla
sta mmusave ; Save the memory configuration
tsx
stx spsave ; Save the system stack ptr
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr
; Allow some re-entrancy by skipping the next task if it already was done.
; This sometimes can let us rerun the program without reloading it.
; Call the module constructors.
ldx move_init
beq L0
jsr initlib
; Move the INIT segment from where it was loaded (over the bss segments)
; into where it must be run (over the BSS segment).
jsr moveinit
dec move_init ; Set to false
; Save space by putting some of the start-up code in the INIT segment,
; which can be re-used by the BSS segment, the heap and the C stack.
L0: jsr runinit
; Clear the BSS data.
jsr zerobss
; Push the command-line arguments; and, call main().
@@ -98,14 +93,47 @@ L2: lda zpsave,x
rts
; ------------------------------------------------------------------------
.segment "INIT"
runinit:
; Save the zero-page locations that we need.
ldx #zpspace-1
L1: lda sp,x
sta zpsave,x
dex
bpl L1
; Set up the stack.
lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
sta sp
stx sp+1 ; Set argument stack ptr
; Call the module constructors.
jmp initlib
; ------------------------------------------------------------------------
; Data
.segment "ZPSAVE"
.data
; These two variables were moved out of the BSS segment, and into DATA, because
; we need to use them before INIT is moved off of BSS, and before BSS is zeroed.
mmusave:.res 1
spsave: .res 1
move_init:
.byte 1
.segment "INITBSS"
zpsave: .res zpspace
.bss
spsave: .res 1
mmusave:.res 1

View File

@@ -28,10 +28,9 @@
.include "c64.inc"
MAXARGS = 10 ; Maximum number of arguments allowed
REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name
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
@@ -42,24 +41,24 @@ 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.
;
lda #0 ; The terminating NUL character
ldy FNAM_LEN
cpy #NAME_LEN + 1
bcc L1
ldy #NAME_LEN - 1 ; limit the length
ldy #NAME_LEN ; Limit the length
bne L1 ; Branch always
L0: lda (FNAM),y
sta name,y
L1: dey
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.
beq done ; No "rem," no args.
inx
cmp #REM
bne L2
@@ -71,7 +70,7 @@ next: lda BASIC_BUF,x
beq done ; End of line reached
inx
cmp #' ' ; Skip leading spaces
beq next ;
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
@@ -126,15 +125,13 @@ done: lda #<argv
stx __argv + 1
rts
; These arrays are zeroed before initmainargs is called.
; char name[16+1];
; char* argv[MAXARGS+1]={name};
;
.bss
.segment "INITBSS"
term: .res 1
name: .res NAME_LEN + 1
.data
; char* argv[MAXARGS+1]={name};
argv: .addr name
.res MAXARGS * 2