yea, it compiles but the screen is blank. 30069 is the memory location for the ld a, ** instruction which changes the x coordinate.ParadigmShifter wrote: ↑Mon Mar 18, 2024 3:17 am Not running isn't very helpful Say how it does not work. Did it compile?
If you are using an emulator use the debugger to put breakpoints on the code paths and step through.
My code looks ok to me but it is way past beer o'clock so disclaimers apply.
EDIT: This looks a bit dodgy
ld (30069),a
where did you get 30069 from? Use a label instead of a hardcoded address.
what would this be equivilent to in assembler?
Re: what would this be equivilent to in assembler?
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
- ParadigmShifter
- Manic Miner
- Posts: 673
- Joined: Sat Sep 09, 2023 4:55 am
Re: what would this be equivilent to in assembler?
Self modifying code? You sound like you're only learning, I'd knock that on the head for a good while
If you wanted to modify the operand it would be at the opcode + 1 address anyway?
Never use a hardcoded address anyway, you have an assembler to work that stuff out for you.
If you wanted to modify the operand it would be at the opcode + 1 address anyway?
Never use a hardcoded address anyway, you have an assembler to work that stuff out for you.
Re: what would this be equivilent to in assembler?
yes, thats what i mean. the opcode +1ParadigmShifter wrote: ↑Mon Mar 18, 2024 3:27 am Self modifying code? You sound like you're only learning, I'd knock that on the head for a good while
If you wanted to modify the operand it would be at the opcode + 1 address anyway?
Never use a hardcoded address anyway, you have an assembler to work that stuff out for you.
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
- ParadigmShifter
- Manic Miner
- Posts: 673
- Joined: Sat Sep 09, 2023 4:55 am
Re: what would this be equivilent to in assembler?
Ok well don't do that when you are learning. It's an advanced optimisation technique which makes the code harder to understand and debug. I can't see any need for it here either, keyboard reading is negligible jiffyswise compared to drawing stuff and ting.
Always use a label anyway...
Always use a label anyway...
Re: what would this be equivilent to in assembler?
ok, ive changed that to a label and ive retyped the code so now it works apart from the character still wont move left...ParadigmShifter wrote: ↑Mon Mar 18, 2024 3:31 am Ok well don't do that when you are learning. It's an advanced optimisation technique which makes the code harder to understand and debug. I can't see any need for it here either, keyboard reading is negligible jiffyswise compared to drawing stuff and ting.
Always use a label anyway...
Code: Select all
;
; ROM routine addresses
;
ROM_CLS EQU 0x0DAF ; Clears the screen and opens channel 2
ROM_OPEN_CHANNEL EQU 0x1601 ; Open a channel
ROM_PRINT EQU 0x203C ; Print a string
;
; PRINT control codes - work with ROM_PRINT and RST 0x10
;
INK EQU 0x10
PAPER EQU 0x11
FLASH EQU 0x12
BRIGHT EQU 0x13
INVERSE EQU 0x14
OVER EQU 0x15
AT1 EQU 0x16
TAB EQU 0x17
CR EQU 0x0C
;
; Or this...
;
org 30000
Key equ $7ffe ; Keyboard half row for Space, Sybmbol Shift, M, N, and B
Key2 equ $fefe ; Keyboard half row
Xcoordinate db 0 ; Location to store X (0..255)
xpos db 0
loop
IncreaseX ld bc, Key ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row with Space, Sybmbol Shift, M, N, and B
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM ; A will only be zero if X key is pressed
inc a
cp 31 ; A < 32?
jr nc, notM ; A >= 32 : do not write back new value of Xcoordinate ; X = X + 1
ld (Xcoordinate), a ; Save new value of X back for next time
DecreaseX ld bc, Key2 ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM ; A will only be zero if X key is pressed
or a
jr z, notM
dec a ; X = X - 1
ld (Xcoordinate), a ; Save new value of X back for next time
notM ; X is now in A register so we can do something with it next
ld (xpos),a
; You can either do this...
;
CALL ROM_CLS ; Clear screen and open Channel 2 (Screen
; Print a single character at screen position (15, 1)
;
LD A, AT1 ; AT control character
RST 0x10
LD A, 10 ; Y
RST 0x10
LD A, (xpos) ; X
RST 0x10
LD A, INK ; Ink colour
RST 0x10
LD A, 0 ; Red
RST 0x10
LD A, 65 ; Character to print
RST 0x10
jp loop
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
- ParadigmShifter
- Manic Miner
- Posts: 673
- Joined: Sat Sep 09, 2023 4:55 am
Re: what would this be equivilent to in assembler?
Isn't xpos same as Xcoordinate? You haven't shown where you defined xpos.
You probably want to remove that and replace the LD A, (xpos) with LD A, (Xcoordinate) instead.
EDIT: Ok I see where you define xpos... you don't update that though only Xcoordinate.
EDIT2: You kind of update it but you are using A register to update it which is flipping between keyboard reading and reading the x position. Get rid and use Xcoordinate instead since you set that to the the correct value. You seem to be updating xpos incorrectly if a key is not pressed.
If you are not pressing the key A register has nonsense in it, basically.
You probably want to remove that and replace the LD A, (xpos) with LD A, (Xcoordinate) instead.
EDIT: Ok I see where you define xpos... you don't update that though only Xcoordinate.
EDIT2: You kind of update it but you are using A register to update it which is flipping between keyboard reading and reading the x position. Get rid and use Xcoordinate instead since you set that to the the correct value. You seem to be updating xpos incorrectly if a key is not pressed.
If you are not pressing the key A register has nonsense in it, basically.
Re: what would this be equivilent to in assembler?
ok, ive done that but it still wont move to the left...ParadigmShifter wrote: ↑Mon Mar 18, 2024 3:45 am Isn't xpos same as Xcoordinate? You haven't shown where you defined xpos.
You probably want to remove that and replace the LD A, (xpos) with LD A, (Xcoordinate) instead.
EDIT: Ok I see where you define xpos... you don't update that though only Xcoordinate.
EDIT2: You kind of update it but you are using A register to update it which is flipping between keyboard reading and reading the x position. Get rid and use Xcoordinate instead since you set that to the the correct value. You seem to be updating xpos incorrectly if a key is not pressed.
If you are not pressing the key A register has nonsense in it, basically.
Code: Select all
;
; ROM routine addresses
;
ROM_CLS EQU 0x0DAF ; Clears the screen and opens channel 2
ROM_OPEN_CHANNEL EQU 0x1601 ; Open a channel
ROM_PRINT EQU 0x203C ; Print a string
;
; PRINT control codes - work with ROM_PRINT and RST 0x10
;
INK EQU 0x10
PAPER EQU 0x11
FLASH EQU 0x12
BRIGHT EQU 0x13
INVERSE EQU 0x14
OVER EQU 0x15
AT1 EQU 0x16
TAB EQU 0x17
CR EQU 0x0C
;
; Or this...
;
org 30000
Key equ $7ffe ; Keyboard half row for Space, Sybmbol Shift, M, N, and B
Key2 equ $fefe ; Keyboard half row
Xcoordinate db 0 ; Location to store X (0..255)
loop
IncreaseX ld bc, Key ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row with Space, Sybmbol Shift, M, N, and B
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM ; A will only be zero if X key is pressed
inc a
cp 31 ; A < 32?
jr nc, notM ; A >= 32 : do not write back new value of Xcoordinate ; X = X + 1
ld (Xcoordinate), a ; Save new value of X back for next time
DecreaseX ld bc, Key2 ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM ; A will only be zero if X key is pressed
or a
jr z, notM
dec a ; X = X - 1
ld (Xcoordinate), a ; Save new value of X back for next time
notM ; X is now in A register so we can do something with it next
; You can either do this...
;
CALL ROM_CLS ; Clear screen and open Channel 2 (Screen
; Print a single character at screen position (15, 1)
;
LD A, AT1 ; AT control character
RST 0x10
LD A, 10 ; Y
RST 0x10
LD A, (Xcoordinate) ; X
RST 0x10
LD A, INK ; Ink colour
RST 0x10
LD A, 0 ; Red
RST 0x10
LD A, 65 ; Character to print
RST 0x10
jp loop
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
1 plot rnd*255,rnd*175
2 goto 1
http://zxspeccy.great-site.net/
- ParadigmShifter
- Manic Miner
- Posts: 673
- Joined: Sat Sep 09, 2023 4:55 am
Re: what would this be equivilent to in assembler?
It looks like you are only checking for left if you also pressed right...you are jumping too far forward, over the keypress check for left if you aren't pressing right.
So you want to jump to DecreaseX in some cases as well. EDIT: That's also a terrible name, CheckPressingLeft would be better
So you want to jump to DecreaseX in some cases as well. EDIT: That's also a terrible name, CheckPressingLeft would be better
- MustardTiger
- Microbot
- Posts: 124
- Joined: Tue May 02, 2023 8:05 pm
Re: what would this be equivilent to in assembler?
As ParadigmShifter said, you're jumping too far ahead if the first key isn't pressed.
I think you would find it easier if you moved the three parts of your code into seperate functions. Like below. Then when you add IncreaseY and DecreaseY it will be simple to understand the flow of your code.
I think you would find it easier if you moved the three parts of your code into seperate functions. Like below. Then when you add IncreaseY and DecreaseY it will be simple to understand the flow of your code.
Code: Select all
;
; ROM routine addresses
;
ROM_CLS EQU 0x0DAF ; Clears the screen and opens channel 2
ROM_OPEN_CHANNEL EQU 0x1601 ; Open a channel
ROM_PRINT EQU 0x203C ; Print a string
;
; PRINT control codes - work with ROM_PRINT and RST 0x10
;
INK EQU 0x10
PAPER EQU 0x11
FLASH EQU 0x12
BRIGHT EQU 0x13
INVERSE EQU 0x14
OVER EQU 0x15
AT1 EQU 0x16
TAB EQU 0x17
CR EQU 0x0C
;
; Or this...
;
org 30000
Key equ $7ffe ; Keyboard half row for Space, Sybmbol Shift, M, N, and B
Key2 equ $fefe ; Keyboard half row
Xcoordinate db 0 ; Location to store X (0..255)
loop call IncreaseX
call DecreaseX
call Draw
jr loop
IncreaseX ld bc, Key ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row with Space, Sybmbol Shift, M, N, and B
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM ; A will only be zero if X key is pressed
inc a
cp 31 ; A < 32?
jr nc, notM ; A >= 32 : do not write back new value of Xcoordinate ; X = X + 1
ld (Xcoordinate), a ; Save new value of X back for next time
notM ret
DecreaseX ld bc, Key2 ; Bit 0 = Space, bit 4 = B
in a, (c) ; Read kb half row
and %00100 ; Clear all bits except for M
ld a, (Xcoordinate) ; Read existing value of X
jr nz, notM2 ; A will only be zero if X key is pressed
or a
jr z, notM2
dec a ; X = X - 1
ld (Xcoordinate), a ; Save new value of X back for next time
notM2 ; X is now in A register so we can do something with it next
ret
Draw
; You can either do this...
;
CALL ROM_CLS ; Clear screen and open Channel 2 (Screen
; Print a single character at screen position (15, 1)
;
LD A, AT1 ; AT control character
RST 0x10
LD A, 10 ; Y
RST 0x10
LD A, (Xcoordinate) ; X
RST 0x10
LD A, INK ; Ink colour
RST 0x10
LD A, 0 ; Red
RST 0x10
LD A, 65 ; Character to print
RST 0x10
ret