Skip to content

Commit

Permalink
inc/dec support for self-modifying code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Griffini committed Jul 5, 2012
1 parent f9c3257 commit ee87c81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions 6502.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ function clv(m) { return "v=0;"; }
function cmp(m) { ssz("w"); return "c=(a>="+m+");w=(a-"+m+")&255;"; }
function cpx(m) { ssz("w"); return "c=(x>="+m+");w=(x-"+m+")&255;"; }
function cpy(m) { ssz("w"); return "c=(y>="+m+");w=(y-"+m+")&255;"; }
function dec(m) { ssz(m); return m+"=("+m+"-1)&255;"; }
function dec(m) { ssz(m); return "maykill("+m.substr(2,m.length-3)+");"+m+"=("+m+"-1)&255;if(!alive){ip="+ip+";return;}"; }
function dex(m) { ssz("x"); return "x=(x-1)&255;"; }
function dey(m) { ssz("y"); return "y=(y-1)&255;"; }
function eor(m) { ssz("a"); return "a^="+m+";"; }
function inc(m) { ssz(m); return m+"=("+m+"+1)&255;"; }
function inc(m) { ssz(m); return "maykill("+m.substr(2,m.length-3)+");"+m+"=("+m+"+1)&255;if(!alive){ip="+ip+";return;}"; }
function inx(m) { ssz("x"); return "x=(x+1)&255;"; }
function iny(m) { ssz("y"); return "y=(y+1)&255;"; }
function jmp(m) { return fsz()+"ip="+m+"; return;"; }
Expand Down Expand Up @@ -271,7 +271,7 @@ function jit()
{
var count = 0, code = "(function(){";
var ip0 = ip, addr;
var NN = 100;
var NN = 2;
while (count < NN)
{
count += 1;
Expand Down
15 changes: 10 additions & 5 deletions demo2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ start:
; "Regular" non-self-modifying code
;
ldx #$00
ldy #$00
ldy #$10
lda #$00
sta set_row
sta set_col
loop1:
stx write_pixel
inx
sta write_pixel
clc
adc #$01
bne loop1
iny
dex
bne loop1
clc
adc #$01
dey
bne loop1
jmp $0300

Expand All @@ -43,14 +47,15 @@ loop1:
; Self-modifying code
;
ldx #$00
ldy #$00
ldy #$10
loop2:
lda #$00 ; <----- $00 will be incremented!
sta write_pixel
inc $0305
bne loop2
dex
bne loop2
inc $0305
dey
bne loop2
jmp $0000

0 comments on commit ee87c81

Please sign in to comment.