mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-03-20 00:32:25 +00:00
fixed verilog scope updating when clicked
This commit is contained in:
parent
2dbc60aa2e
commit
318c4d8413
@ -14,6 +14,16 @@
|
||||
.org 0x8000
|
||||
.len 32768
|
||||
|
||||
.define RegSwitches $fffe
|
||||
.define RegFlags $ffff
|
||||
|
||||
.define KeyP1Left 1
|
||||
.define KeyP1Right 2
|
||||
.define KeyP1Up 4
|
||||
.define KeyP1Down 8
|
||||
.define KeyP1Btn1 16
|
||||
.define KeyP1Btn2 32
|
||||
|
||||
.define ScreenBuffer $6000
|
||||
.define PageTable $7e00
|
||||
.define SpriteTable $7f00
|
||||
@ -140,70 +150,136 @@ MoveSprites:
|
||||
mov dx,@SpriteTable
|
||||
mov cx,#5
|
||||
MoveSLoop:
|
||||
mov fx,@MoveSprite
|
||||
jsr fx
|
||||
add dx,#2
|
||||
dec cx
|
||||
bnz MoveSLoop
|
||||
rts
|
||||
MoveSprite:
|
||||
; get sprite position
|
||||
mov ax,[dx] ; x/y pos
|
||||
; get direction sprite is moving
|
||||
mov bx,[dx+1] ; direction
|
||||
rol bx
|
||||
rol bx
|
||||
rol bx
|
||||
rol bx
|
||||
rol bx
|
||||
and bx,#3 ; bx = direction (0-3)
|
||||
add bx,@DirectionXY
|
||||
add ax,[bx] ; lookup & add to x/y
|
||||
; is sprite in middle of a lane?
|
||||
mov ex,ax
|
||||
and ex,@$0707
|
||||
sub ex,@$0404
|
||||
bnz JustUpdatePos ; no, just move
|
||||
; is this the player?
|
||||
mov fx,dx
|
||||
sub fx,@SpriteTable
|
||||
bnz NotPlayerMove
|
||||
mov fx,@MovePlayer
|
||||
jsr fx
|
||||
NotPlayerMove:
|
||||
; make sure we don't collide with wall
|
||||
mov ex,ax
|
||||
add ex,#$08
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex ; divide X by 8
|
||||
and ex,#31
|
||||
mov fx,ex
|
||||
mov fx,ex ; fx = X/8
|
||||
mov ex,ax
|
||||
add ex,@$0800
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex ; divide Y by 64
|
||||
lsr ex ; ex = Y/64
|
||||
and ex,@$ffe0
|
||||
or ex,fx
|
||||
or ex,fx ; ex = screen offset
|
||||
add bx,@DirectionCells
|
||||
add ex,[bx] ; add direction offset
|
||||
sub bx,@DirectionCells
|
||||
add ex,#33 ; add +1 right and +1 down
|
||||
add ex,@ScreenBuffer
|
||||
mov fx,[ex]
|
||||
and fx,@$ff00
|
||||
xor fx,@$0500
|
||||
bz DoNotUpdatePos
|
||||
; update x/y position
|
||||
bz ChooseNewDirection
|
||||
mov fx,#0
|
||||
mov [ex],fx ; eat dots
|
||||
JustUpdatePos:
|
||||
; update x/y position
|
||||
add bx,@DirectionXY
|
||||
add ax,[bx] ; lookup & add to x/y
|
||||
mov [dx],ax ; store x/y pos
|
||||
NextSLoop:
|
||||
add dx,#2
|
||||
dec cx
|
||||
bnz MoveSLoop
|
||||
rts
|
||||
; Choose a new direction
|
||||
DoNotUpdatePos:
|
||||
add dx,#1
|
||||
ChooseNewDirection:
|
||||
mov fx,dx
|
||||
sub fx,@SpriteTable
|
||||
bnz NotPlayer
|
||||
rts
|
||||
NotPlayer:
|
||||
inc dx
|
||||
mov bx,[dx] ; direction
|
||||
add bx,@$1000
|
||||
mov [dx],bx
|
||||
sub dx,#1
|
||||
jmp NextSLoop
|
||||
dec dx
|
||||
rts
|
||||
MovePlayer:
|
||||
mov fx,@RegSwitches
|
||||
mov fx,[fx]
|
||||
SwitchLoop:
|
||||
mov ex,#0
|
||||
lsr fx
|
||||
bcs PlyrMove
|
||||
mov ex,#2
|
||||
lsr fx
|
||||
bcs PlyrMove
|
||||
mov ex,#3
|
||||
lsr fx
|
||||
bcs PlyrMove
|
||||
mov ex,#1
|
||||
lsr fx
|
||||
bcs PlyrMove
|
||||
rts
|
||||
PlyrMove:
|
||||
mov bx,ex
|
||||
mov fx,bx
|
||||
lsr fx
|
||||
ror fx
|
||||
ror fx
|
||||
ror fx
|
||||
ror fx
|
||||
inc dx
|
||||
mov ex,[dx] ; direction
|
||||
and ex,@$0fff
|
||||
or ex,fx
|
||||
mov [dx],ex
|
||||
dec dx
|
||||
rts
|
||||
|
||||
HelloWorld:
|
||||
.string HELLO WORLD
|
||||
.data 0
|
||||
|
||||
SpriteInitData:
|
||||
.data $b373 $1233
|
||||
.data $8363 $3456
|
||||
.data $8373 $4567
|
||||
.data $8383 $5678
|
||||
.data $8373 $1234
|
||||
.data $b474 $0033
|
||||
.data $8464 $0056
|
||||
.data $8474 $1067
|
||||
.data $8484 $2078
|
||||
.data $8474 $3034
|
||||
|
||||
DirectionXY:
|
||||
.data $FFFF
|
||||
.data $0100
|
||||
.data $0001
|
||||
.data $FF00
|
||||
.data -1
|
||||
.data 256
|
||||
.data 1
|
||||
.data -256
|
||||
|
||||
DirectionCells:
|
||||
.data -1
|
||||
.data 32
|
||||
.data 1
|
||||
.data -32
|
||||
|
||||
MazeData:
|
||||
.data $3111 $1111 $1111 $1114 $3111 $1111 $1111 $1114
|
||||
|
@ -346,11 +346,31 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
var trace = fps < 0.02;
|
||||
updateVideoFrameCycles(cyclesPerFrame * fps/60 + 1, sync, trace);
|
||||
//if (trace) displayTraceBuffer();
|
||||
self.restartDebugState();
|
||||
gen.__unreset();
|
||||
refreshVideoFrame();
|
||||
}
|
||||
|
||||
function refreshVideoFrame() {
|
||||
updateInspectionFrame();
|
||||
updateAnimateScope();
|
||||
updateInspectionPostFrame();
|
||||
self.restartDebugState();
|
||||
gen.__unreset();
|
||||
}
|
||||
|
||||
function updateFrame() {
|
||||
if (!gen) return;
|
||||
if (gen.vsync !== undefined && gen.hsync !== undefined && gen.rgb !== undefined)
|
||||
updateVideoFrame();
|
||||
else
|
||||
updateScopeFrame();
|
||||
}
|
||||
|
||||
function refreshFrame() {
|
||||
if (!gen) return;
|
||||
if (gen.vsync !== undefined && gen.hsync !== undefined && gen.rgb !== undefined)
|
||||
refreshVideoFrame();
|
||||
else
|
||||
refreshScopeOverlay(trace_ports);
|
||||
}
|
||||
|
||||
function updateAnimateScope() {
|
||||
@ -366,7 +386,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
ctx.fillRect(framex, framey+vidyoffset, 1, 1);
|
||||
scope_index_offset = (trace_index - trace_signals.length*scopeWidth + trace_buffer.length) % trace_buffer.length;
|
||||
scope_x_offset = 0;
|
||||
updateScopeOverlay(trace_signals);
|
||||
refreshScopeOverlay(trace_signals);
|
||||
} else {
|
||||
video.updateFrame();
|
||||
scope_index_offset = 0;
|
||||
@ -432,10 +452,10 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
if (!dirty) return;
|
||||
dirty = false;
|
||||
scope_y_top = 0;
|
||||
updateScopeOverlay(trace_ports);
|
||||
refreshScopeOverlay(trace_ports);
|
||||
}
|
||||
|
||||
function updateScopeOverlay(arr) {
|
||||
function refreshScopeOverlay(arr) {
|
||||
if (!sdata) {
|
||||
scopeImageData = video.getContext().createImageData(scopeWidth,scopeHeight);
|
||||
sdata = new Uint32Array(scopeImageData.data.buffer);
|
||||
@ -518,7 +538,6 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
}
|
||||
|
||||
this.start = function() {
|
||||
// TODO
|
||||
video = new RasterVideo(mainElement,videoWidth,videoHeight);
|
||||
video.create();
|
||||
var ctx = video.getContext();
|
||||
@ -526,36 +545,36 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
ctx.fillStyle = "white";
|
||||
ctx.textAlign = "left";
|
||||
setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP);
|
||||
// TODO: make it stop incrementing time when clicked
|
||||
$(video.canvas).mousemove(function(e) {
|
||||
var new_x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 20);
|
||||
var new_y = Math.floor(e.offsetY * video.canvas.height / $(video.canvas).height() - 20);
|
||||
var vcanvas = $(video.canvas);
|
||||
vcanvas.mousemove(function(e) {
|
||||
var new_x = Math.floor(e.offsetX * video.canvas.width / vcanvas.width() - 20);
|
||||
var new_y = Math.floor(e.offsetY * video.canvas.height / vcanvas.height() - 20);
|
||||
if (mouse_pressed) {
|
||||
scope_y_offset = clamp(Math.min(0,-scope_max_y+videoHeight), 0, scope_y_offset + new_y - paddle_y);
|
||||
scope_time_x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 16);
|
||||
scope_time_x = Math.floor(e.offsetX * video.canvas.width / vcanvas.width() - 16);
|
||||
dirty = true;
|
||||
redrawFrame();
|
||||
refreshFrame();
|
||||
}
|
||||
paddle_x = clamp(8, 240, new_x);
|
||||
paddle_y = clamp(8, 240, new_y);
|
||||
});
|
||||
$(video.canvas).mousedown(function(e) {
|
||||
scope_time_x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 16);
|
||||
vcanvas.mousedown(function(e) {
|
||||
scope_time_x = Math.floor(e.offsetX * video.canvas.width / vcanvas.width() - 16);
|
||||
mouse_pressed = true;
|
||||
if (e.target.setCapture) e.target.setCapture(); // TODO: pointer capture
|
||||
dirty = true;
|
||||
redrawFrame();
|
||||
refreshFrame();
|
||||
});
|
||||
$(video.canvas).mouseup(function(e) {
|
||||
vcanvas.mouseup(function(e) {
|
||||
mouse_pressed = false;
|
||||
if (e.target.setCapture) e.target.releaseCapture(); // TODO: pointer capture
|
||||
dirty = true;
|
||||
redrawFrame();
|
||||
refreshFrame();
|
||||
});
|
||||
$(video.canvas).keydown(function(e) {
|
||||
vcanvas.keydown(function(e) {
|
||||
switch (e.keyCode) {
|
||||
case 37: scope_time_x--; dirty=true; redrawFrame(); break;
|
||||
case 39: scope_time_x++; dirty=true; redrawFrame(); break;
|
||||
case 37: scope_time_x--; dirty=true; refreshFrame(); break;
|
||||
case 39: scope_time_x++; dirty=true; refreshFrame(); break;
|
||||
}
|
||||
});
|
||||
idata = video.getFrameData();
|
||||
@ -563,19 +582,12 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
if (!self.isRunning())
|
||||
return;
|
||||
gen.switches = switches[0];
|
||||
redrawFrame();
|
||||
updateFrame();
|
||||
};
|
||||
trace_buffer = new Uint32Array(0x10000);
|
||||
self.setFrameRate(60);
|
||||
}
|
||||
|
||||
function redrawFrame() {
|
||||
if (gen.vsync !== undefined && gen.hsync !== undefined && gen.rgb !== undefined)
|
||||
updateVideoFrame();
|
||||
else
|
||||
updateScopeFrame();
|
||||
}
|
||||
|
||||
this.printErrorCodeContext = function(e, code) {
|
||||
if (e.lineNumber && e.message) {
|
||||
var lines = code.split('\n');
|
||||
|
Loading…
x
Reference in New Issue
Block a user