|
Post by mirkosoft on Mar 31, 2015 8:16:43 GMT
Z80 CPU allows user to read and write Program Counter. Really I see not opcode allowing this in 8502 (or 65xx) programming, but after start of Monitor built-in C128 it writes to screen 16-bit address in Program Counter. So, I mean it must to be possible 'cause every code - Kernal, Monitor, Basic and all is written in 8502 code... Where to get routine with PC output or better how to read/write PC? Z80 CPU has opcodes doing it.
Thank you for all.
Miro
|
|
|
Post by hydrophilic on Apr 1, 2015 7:33:20 GMT
Easy to write PC (Program Counter)... just execute JMP Address (opcode $4c + low_byte + high_byte) Another easy way to write PC is execute JSR Address (opcode $20 + low_byte + high_byte)... only difference is "return address" is saved on the stack. To read PC is not directly possible... but with simple code you can do it.... Just place some "special" code that is available *everywhere* (for example page 0 (ZP) or page 1 (stack)) and do JSR to the special code... The "special" code just needs to examine the CPU Stack to see the "return address"... that address is where the "main" code is running... OMG... how can I explain? So here is simple program... ;"special" code available "everywhere" ;located near bottom of CPU stack .0140 tsx .0141 lda $101,x .0144 ldy $102,x .0147 rts
;stupid "test" code .1300 jsr $140 .1303 ... ; now .Y=address_high of PC and .A=address_low of PC (when JSR $140 was executed)
Just note, the return registers (Y=PC_High, A=PC_Low) will be the JSR address +2...
so for example, the code at $1300 (JSR $140) will return with .YA = $1302... which is JSR code address ($1300) plus 2.
God I hope that makes sense!!!!!!! If not, please ask and I will try to explain again :/
|
|