NSC: More comments

This commit is contained in:
Joshua Bell 2017-11-26 16:52:28 -08:00
parent 95f029fc30
commit 6ee08e5c89

View File

@ -1,6 +1,9 @@
.setcpu "65C02" .setcpu "6502"
.linecont + .linecont +
.include "apple2.inc"
.include "opcodes.inc"
;; ASCII ;; ASCII
BELL := $07 BELL := $07
CR := $0D CR := $0D
@ -9,10 +12,7 @@ CR := $0D
MAX_DW := $FFFF MAX_DW := $FFFF
;; Softswitches ;; Softswitches
KBD := $C000 ; Last Key Pressed + 128
KBDSTRB := $C010 ; Keyboard Strobe
CLR80VID := $C00C ; 40 Columns CLR80VID := $C00C ; 40 Columns
CLRALTCHAR := $C00E ; Primary Character Set
ROMIN2 := $C082 ; Read ROM; no write ROMIN2 := $C082 ; Read ROM; no write
RWRAM1 := $C08B ; Read/write RAM bank 1 RWRAM1 := $C08B ; Read/write RAM bank 1
@ -21,6 +21,7 @@ PRODOS := $BF00
DATETIME := $BF06 DATETIME := $BF06
DEVNUM := $BF30 DEVNUM := $BF30
BITMAP := $BF58 BITMAP := $BF58
BITMAP_SIZE := 24 ; 24 bytes in bitmap
DATELO := $BF90 DATELO := $BF90
TIMELO := $BF92 TIMELO := $BF92
MACHID := $BF98 MACHID := $BF98
@ -49,7 +50,7 @@ SETNORM := $FE84
SETKBD := $FE89 SETKBD := $FE89
SETVID := $FE93 SETVID := $FE93
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
.macro PASCAL_STRING arg .macro PASCAL_STRING arg
.byte .strlen(arg) .byte .strlen(arg)
@ -77,20 +78,20 @@ SETVID := $FE93
.define HI(c) ((c)|$80) .define HI(c) ((c)|$80)
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
data_buffer = $1800 data_buffer = $1800
.define SYSTEM_SUFFIX ".SYSTEM" .define SYSTEM_SUFFIX ".SYSTEM"
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
.org $1000 .org $1000
;; Loaded at $2000 but relocates to $1000 ;; Loaded at $2000 but relocates to $1000
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
sys_start: sys_start:
sec sec
@ -98,7 +99,7 @@ sys_start:
.byte $04, $21, $91 ; 4/21/91 .byte $04, $21, $91 ; 4/21/91
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Relocate this code from $2000 (.SYSTEM start location) to $1000 ;;; Relocate this code from $2000 (.SYSTEM start location) to $1000
;;; and start executing there. This is done so that the next .SYSTEM ;;; and start executing there. This is done so that the next .SYSTEM
;;; file can be loaded/run at $2000. ;;; file can be loaded/run at $2000.
@ -122,7 +123,7 @@ load: lda src,y ; self-modified
jmp load jmp load
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Identify the name of this SYS file, which should be present at ;;; Identify the name of this SYS file, which should be present at
;;; $280 with or without a path prefix. This is used when searching ;;; $280 with or without a path prefix. This is used when searching
;;; for the next .SYSTEM file to execute. ;;; for the next .SYSTEM file to execute.
@ -156,7 +157,9 @@ cloop: iny
.endproc .endproc
;; Fall through... ;; Fall through...
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Before installing, get the system to a known state and
;;; ensure there is not a previous clock driver installed.
.proc pre_install .proc pre_install
cld cld
@ -170,33 +173,38 @@ cloop: iny
eor #$A5 eor #$A5
sta $03F4 sta $03F4
;; Quit 80-column firmware
lda #$95 ; Ctrl+U (quit 80 col firmware) lda #$95 ; Ctrl+U (quit 80 col firmware)
jsr COUT jsr COUT
ldx #$FF ; Reset stack ;; Reset stack
ldx #$FF
txs txs
sta CLR80VID ; Reset I/O ;; Reset I/O
sta CLR80VID
sta CLRALTCHAR sta CLRALTCHAR
jsr SETVID jsr SETVID
jsr SETKBD jsr SETKBD
jsr SETNORM jsr SETNORM
jsr INIT jsr INIT
ldx #$17 ; Update system page bitmap ;; Update System Bit Map
lda #1 ldx #BITMAP_SIZE-1
lda #%00000001 ; protect page $BF
: sta BITMAP,x : sta BITMAP,x
lda #0 lda #%00000000 ; nothing else protected until...
dex dex
bne :- bne :-
lda #$CF lda #%11001111 ; ZP ($00), stack ($01), text page 1 ($04-$07)
sta BITMAP sta BITMAP
lda MACHID lda MACHID
and #$88 ; //e or //c ? and #$88 ; IIe or IIc (or IIgs) ?
bne :+ bne :+
lda #$DF lda #$DF
sta lowercase_mask ; lower case to upper case sta lowercase_mask ; lower case to upper case
: lda MACHID : lda MACHID
and #$01 ; existing clock card? and #$01 ; existing clock card?
beq detect_nsc ; nope, check for NSC beq detect_nsc ; nope, check for NSC
@ -208,7 +216,7 @@ cloop: iny
jmp launch_next_sys_file jmp launch_next_sys_file
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Detect NSC. Scan slot ROMs and main ROMs. Try reading ;;; Detect NSC. Scan slot ROMs and main ROMs. Try reading
;;; each location several times, and validate results before ;;; each location several times, and validate results before
;;; installing driver. ;;; installing driver.
@ -306,7 +314,7 @@ tries: .byte 3
slot: .byte 0 slot: .byte 0
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Install NSC Driver. Copy into address at DATETIME vector, ;;; Install NSC Driver. Copy into address at DATETIME vector,
;;; update the vector and update MACHID bits to signal a clock ;;; update the vector and update MACHID bits to signal a clock
;;; is present. ;;; is present.
@ -317,7 +325,7 @@ slot: .byte 0
lda DATETIME+1 lda DATETIME+1
sta ptr sta ptr
clc clc
adc #$73 adc #(unlock - driver - 1)
sta ld3+1 sta ld3+1
lda DATETIME+2 lda DATETIME+2
sta ptr+1 sta ptr+1
@ -337,7 +345,7 @@ loop: lda driver,y
ora #$01 ora #$01
sta MACHID sta MACHID
lda #$4C ; JMP opcode lda #OPC_JMP_abs
sta DATETIME sta DATETIME
;; Invoke the driver to init the time ;; Invoke the driver to init the time
@ -377,7 +385,7 @@ loop: lda driver,y
jsr CROUT jsr CROUT
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Find and invoke the next .SYSTEM file ;;; Find and invoke the next .SYSTEM file
.proc launch_next_sys_file .proc launch_next_sys_file
@ -523,7 +531,7 @@ not_found:
jmp quit jmp quit
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Output a high-ascii, null-terminated string. ;;; Output a high-ascii, null-terminated string.
;;; String immediately follows the JSR. ;;; String immediately follows the JSR.
@ -555,7 +563,7 @@ skip: inc ptr
rts rts
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; COUT a 2-digit number in A ;;; COUT a 2-digit number in A
.proc cout_number .proc cout_number
@ -581,12 +589,13 @@ units: pla
rts rts
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
lowercase_mask: lowercase_mask:
.byte $FF ; Set to $DF on systems w/o lower-case .byte $FF ; Set to $DF on systems w/o lower-case
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Invoke ProDOS QUIT routine.
.proc quit .proc quit
PRODOS_CALL MLI_QUIT, quit_params PRODOS_CALL MLI_QUIT, quit_params
@ -601,7 +610,8 @@ lowercase_mask:
.endproc .endproc
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Read a disk block.
.proc read_block .proc read_block
PRODOS_CALL MLI_READ_BLOCK, read_block_params PRODOS_CALL MLI_READ_BLOCK, read_block_params
@ -618,7 +628,7 @@ block_num: .word 2 ; block_num - block 2 is volume directory
read_block_params_unit_num := read_block_params::unit_num read_block_params_unit_num := read_block_params::unit_num
read_block_params_block_num := read_block_params::block_num read_block_params_block_num := read_block_params::block_num
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Load/execute the system file in PATHNAME ;;; Load/execute the system file in PATHNAME
.proc invoke_system_file .proc invoke_system_file
@ -637,8 +647,8 @@ block_num: .word 2 ; block_num - block 2 is volume directory
jmp SYS_ADDR ; Invoke loaded SYSTEM file jmp SYS_ADDR ; Invoke loaded SYSTEM file
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Error Handler ;;; Error handler - invoked if any ProDOS error occurs.
.proc on_error .proc on_error
pha pha
@ -655,7 +665,7 @@ block_num: .word 2 ; block_num - block 2 is volume directory
jmp quit jmp quit
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
.proc open_params .proc open_params
.byte 3 ; param_count .byte 3 ; param_count
@ -679,7 +689,7 @@ ref_num:.byte 1 ; ref_num
ref_num:.byte 0 ; ref_num ref_num:.byte 0 ; ref_num
.endproc .endproc
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
found_self_flag: found_self_flag:
.byte 0 .byte 0
@ -689,8 +699,8 @@ suffix: .byte SYSTEM_SUFFIX
self_name: self_name:
PASCAL_STRING "NS.CLOCK.SYSTEM" PASCAL_STRING "NS.CLOCK.SYSTEM"
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; NSC driver - copied into ProDOS ;;; NSC driver - modified as needed and copied into ProDOS
driver: driver:
php php
@ -700,59 +710,74 @@ ld4: lda $CFFF ; self-modified
st1: sta $C300 ; self-modified st1: sta $C300 ; self-modified
ld1: lda $C304 ; self-modified ld1: lda $C304 ; self-modified
ldx #8 ldx #8
L140D:
;; Unlock the NSC by bit-banging.
uloop:
ld3: lda unlock-1,x ; self-modified ld3: lda unlock-1,x ; self-modified
sec sec
ror a ror a ; a bit at a time
L1412: pha : pha
lda #0 lda #0
rol a rol a
tay tay
ld2: lda $C300,y ; self-modified ld2: lda $C300,y ; self-modified
pla pla
lsr a lsr a
bne L1412 bne :-
dex dex
bne L140D bne uloop
;; Read 8 bytes * 8 bits of clock data into $200...$207
ldx #8 ldx #8
L1423: ldy #8 bloop: ldy #8
st2: st2:
: lda $C304 ; self-modified : lda $C304 ; self-modified
ror a ror a
ror $01FF,x ror $01FF,x
dey dey
bne :- bne :-
lda $01FF,x lda $01FF,x ; got 8 bits
lsr a
lsr a lsr a ; BCD to binary
lsr a ; shift out tens
lsr a lsr a
lsr a lsr a
tay tay
beq L1447 beq donebcd
lda $01FF,x lda $01FF,x
and #$0F and #$0F ; mask out units
clc clc
: adc #$0A : adc #10 ; and add tens as needed
dey dey
bne :- bne :-
sta $01FF,x sta $01FF,x
L1447: dex donebcd:
bne L1423 dex
lda $0204 bne bloop
;; Now $200...$207 is y/m/d/w/H/M/S/f
;; Update ProDOS date/time.
lda $0204 ; hour
sta TIMELO+1 sta TIMELO+1
lda $0205
lda $0205 ; minute
sta TIMELO sta TIMELO
lda $0201
lda $0201 ; month
asl a asl a
asl a asl a
asl a asl a
asl a asl a
asl a asl a
ora $0202
ora $0202 ; day
sta DATELO sta DATELO
lda $0200
lda $0200 ; year
rol a rol a
sta DATELO+1 sta DATELO+1
pla pla
bmi done bmi done
st4: sta $CFFF ; self-modified st4: sta $CFFF ; self-modified
@ -767,11 +792,11 @@ unlock:
sizeof_driver := * - driver sizeof_driver := * - driver
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
sys_end: sys_end:
;;; -------------------------------------------------- ;;; ------------------------------------------------------------
;;; Junk from here on... ;;; Junk from here on...
.byte $b3, $68, $72, $f0, $2a, $2a, $2a, $2a .byte $b3, $68, $72, $f0, $2a, $2a, $2a, $2a