summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--date.s36
-rw-r--r--instructions/LSR.ts1
-rw-r--r--runtime.ts8
4 files changed, 43 insertions, 5 deletions
diff --git a/README.md b/README.md
index 5a6ff4c..37c870a 100644
--- a/README.md
+++ b/README.md
@@ -28,4 +28,5 @@ commands:
  - `k[NUM]` - skip
  - `r[ADR]` - breakpoint
  - `g[ADR]` - goto, change PC
- - `I[INS]` - breakpoint instruction
\ No newline at end of file
+ - `I[INS]` - breakpoint instruction
+ 
\ No newline at end of file
diff --git a/date.s b/date.s
new file mode 100644
index 0000000..afd6717
--- /dev/null
+++ b/date.s
@@ -0,0 +1,36 @@
+;* This routine works for any date from 1900-03-01 to 2155-12-31.
+;* No range checking is done, so validate input before calling.
+;*
+;* I use the formula
+;*     Weekday = (day + offset[month] + year + year/4 + fudge) mod 7
+;* where the value of fudge depends on the century.
+;*
+;* Input: Y = year (0=1900, 1=1901, ..., 255=2155)
+;*        X = month (1=Jan, 2=Feb, ..., 12=Dec)
+;*        A = day (1 to 31)
+;*
+;* Output: Weekday in A (0=Sunday, 1=Monday, ..., 6=Saturday)
+
+TMP      EQU $6          ; Temporary storage
+
+WEEKDAY:
+         CPX #3          ; Year starts in March to bypass
+         BCS MARCH       ; leap year problem
+         DEY             ; If Jan or Feb, decrement year
+MARCH    EOR #$7F        ; Invert A so carry works right
+         CPY #200        ; Carry will be 1 if 22nd century
+         ADC MTAB-1,X    ; A is now day+month offset
+         STA TMP
+         TYA             ; Get the year
+         JSR MOD7        ; Do a modulo to prevent overflow
+         SBC TMP         ; Combine with day+month
+         STA TMP
+         TYA             ; Get the year again
+         LSR             ; Divide it by 4
+         LSR
+         CLC             ; Add it to y+m+d and fall through
+         ADC TMP
+MOD7     ADC #7          ; Returns (A+3) modulo 7
+         BCC MOD7        ; for A in 0..255
+         RTS
+MTAB     DB 1,5,6,3,1,5,3,0,4,2,6,4   	; Month offsets
diff --git a/instructions/LSR.ts b/instructions/LSR.ts
index 61adadb..b907e47 100644
--- a/instructions/LSR.ts
+++ b/instructions/LSR.ts
@@ -8,6 +8,7 @@ export default function (this: The65c02, mode: string) {
         this.zero = result == 0
         this.carry = (mem & 1) != 0
         this.regA.set(result & 0xFF);
+        this.programCounter.increment()
     } else {
         const addr = this.getAddr(mode)
         this.io.address.set(addr);
diff --git a/runtime.ts b/runtime.ts
index 2e6723f..ccb9dae 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -24,13 +24,13 @@ const binStart = parseInt(args.b ?? args.binStart ?? '8000', 16)
 if (Number.isNaN(binStart))
     throw 'binStart is NaN!'
 
-// mem address $0000
-ram[0xFFFC] = binStart & 0x00FF
-ram[0xFFFD] = binStart & 0xFF00
-
 // read code from file
 const code = Deno.readFileSync(args._.toString() || 'msbasic/tmp/eater.bin')
 
+// mem address $0000
+ram[0xFFFC] = binStart & 0x00FF
+ram[0xFFFD] = (binStart & 0xFF00) >> 8
+
 // write code to ram before execution
 for (let offset = 0; offset < code.length; offset++) {
     const byte = code[offset];