OK, I'm slowing doing some bits and pieces in my little Ruby OS to 816-ify it... and there's one little thing that I'm finding just weird. I'm probably missing something completely obvious, but right now can't see it ...
For the most part I'm running in native 816 mode with 8-bit registers.
I have a memory-fill routine. Thought I'd be clever and use the 816 block-move instruction. The code takes the value from the command line via an 'atoi' routine (understands decimal, $hex or %bin) and stores it in a 16-bit memory location in page 0 called atoi0 and atoi1, so then ...
Code:
; Fill 0000 to the start of RubyOs
sei ; Just in-case
lda atoi0
sta $0 ; Store at 0
; '816 fill
aix16
lda #rubyCold-1 ; Number of bytes
ldx #$0000 ; Start
ldy #$0001 ; End
mvn 0,0 ; block move
aix8
jmp rubyOs
The aix8 and aix16 instructions are macros:
Code:
; aix8: aix16:
; Index and A registers into 8 or 16 bit mode
.macro aix8
sep #$30
.i8
.a8
.endmacro
.macro aix16
rep #$30
.i16
.a16
.endmacro
This is ca65 and .a8/16 and .i8/16 are used to indicate to the assembler to use 16 bit or 8 for Acc or XY.
The assembler list output is as I'd expect:
Code:
00018Br 1 A5 EC lda atoi0
00018Dr 1 85 00 sta $0 ; Store at 0
00018Fr 1
00018Fr 1 ; '816 fill
00018Fr 1
00018Fr 1 C2 30 aix16
000191r 1
000191r 1 A9 FF CF lda #rubyCold-1 ; Number of bytes
000194r 1 A2 00 00 ldx #$0000 ; Start
000197r 1 A0 01 00 ldy #$0001 ; End
00019Ar 1 54 00 00 mvn 0,0 ; block move
00019Dr 1
00019Dr 1 E2 30 aix8
00019Fr 1
00019Fr 1 4C rr rr jmp rubyOs
Anyway, here is the odd bit. This works for all values I've tested except zero. If I ask it to fill with zeros, then it crashes in an obscure way and scribbles over memory with a repeating 4-byte pattern: $37, $00, $35, $37 ...
I've tried changing the lda atoi0 with lda #$0 and it fails the same way (but works for other values I've tried).
So have I missed something obvious, being stupid, or something else?
Any clues welcome!
Cheers,
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/