Help with attributes and logical and (z80 assembler)

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
MatGubbins
Manic Miner
Posts: 678
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Help with attributes and logical and (z80 assembler)

Post by MatGubbins »

PeterJ wrote:
Sat Jul 04, 2020 6:16 pm
MatGubbins wrote:
Sat Jul 04, 2020 6:09 pm
Placing quotes around the letters make it easier for you to read. There was also a stray 22,1,0,32 ; at 1,0,"space" at the start.

Great start into the world of machine code Peter!
Thanks @MatGubbins. It's only taken me 35 years and 100s of false starts!

Good idea about improving readability. The printing of a space is to clear the B from Bytes which appears after loading the code.
Ah! I see, so you need the CLS rom routine...or be clever and write a faster one! Hang on, the code is there in your program, just need to change a few numbers and you're there.
0 x
Bomb Munchies Ver2210 4th July 2020 (look for the blue download box ) If you get a time-out message and live in the UK then try after 9pm-3am.
Send me a PM and I can email it to you too. Kent, UK

User avatar
PeterJ
Site Admin
Posts: 2467
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Help with attributes and logical and (z80 assembler)

Post by PeterJ »

Thank you for pointing me in the right direction @MatGubbins, but not giving me the answer. That is a great way to learn. I was clearing the attribute memory, rather than the pixel memory!

Code: Select all

clsscr              
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret
0 x

User avatar
PeterJ
Site Admin
Posts: 2467
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Help with attributes and logical and (z80 assembler)

Post by PeterJ »

Many thanks to you all for the suggestions. My finished code (for this evening) is:

Code: Select all

org $6000

main
    call clsscr
    call border
    call text
    ld hl,22528         ;start of attribute memory
    ld de,32            ;used to jump up and down rows on left and right
    ld b,31             ;counter for columns

top                     ;fill the top row
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    inc hl
    djnz top
    ld b,23

right                   ;fill the right hand side
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    add hl,de
    djnz right
    ld b,31

bottom                  ;fill the bottom
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    dec hl
    djnz bottom
    ld b,23

left                   ;fill the left
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    sbc hl,de
    djnz left

waitkey                 ;From JC Book - Thanks!
    ld hl,23560
    ld (hl),0
wait
    ld a,(hl)
    cp 0
    jr z,wait
    ret

random                  ;From JC Book - Thanks!
    ld hl,(seed)        ;Pointer        
    ld a,h
    and 31              ;keep it within first 8k of ROM.
    ld h,a        
    ld a,(hl)           ;Get "random" number from location.
    inc hl              ;Increment pointer.
    ld (seed),hl
    ret 
seed defw 0

clsscr                  ;Thanks to seven-fff
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret

text                    ;Thanks to seven-fff for the idea
    ld a,2              ;upper screen        
    call 5633           ;open channel        
    ld de,string        ;address of string        
    ld bc,eostr-string  ;length of string to print        
    call 8252           ;print our string        
    ret
string defb 22,7,7,17,0,19,1,16,2,"S",16,6,"P",16,5,"E",16,3,"C",16,7,"T",16,4,"R",16,2,"U",16,6,"M",16,0," "
       defb 16,5,"C",16,3,"O",16,7,"M",16,4,"P",16,2,"U",16,6,"T",16,5,"I",16,3,"N",16,7,"G"
eostr  equ $ 

border
    ld a,0
    out ($FE),a
    ret

END $6000
1 x

User avatar
utz
Dizzy
Posts: 87
Joined: Wed Nov 15, 2017 9:04 am
Contact:

Re: Help with attributes and logical and (z80 assembler)

Post by utz »

PeterJ wrote:
Sat Jul 04, 2020 6:14 pm
Thank you @utz. I will need to look at that one written down in binary so I understand!
Hehe, I was thinking whether I should give an explanation, but I figured you could work it out on your own. And ideed you immediately had the right idea: Looking at the number in binary will give you the answer as to why this works.

That's one reason why I prefer using hexadecimal numbers: They're easier to translate into binary. And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/

Best of luck with your assembly adventures!
2 x

User avatar
MatGubbins
Manic Miner
Posts: 678
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Help with attributes and logical and (z80 assembler)

Post by MatGubbins »

Brilliant. You feel like a king for the day!
1 x
Bomb Munchies Ver2210 4th July 2020 (look for the blue download box ) If you get a time-out message and live in the UK then try after 9pm-3am.
Send me a PM and I can email it to you too. Kent, UK

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1685
Joined: Mon Nov 13, 2017 3:16 pm

Re: Help with attributes and logical and (z80 assembler)

Post by Ast A. Moore »

utz wrote:
Sat Jul 04, 2020 7:48 pm
And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/
Goodness me! After five minutes of utter frustration I realized you could flip the bits by hitting the number keys! (Yeah, I didn’t scroll down for the instructions.) :lol:
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

azesmbog
Berk
Posts: 40
Joined: Sat May 16, 2020 8:43 am

Re: Help with attributes and logical and (z80 assembler)

Post by azesmbog »

PeterJ wrote:
Sat Jul 04, 2020 5:22 pm
Hi,
I wrote a little routine to put random attributes around the border of the screen.
He also wrote a program with colored squares along the border of the screen. only for some reason they were outside the border :)
1 x

User avatar
Lethargeek
Manic Miner
Posts: 273
Joined: Wed Dec 11, 2019 6:47 am

Re: Help with attributes and logical and (z80 assembler)

Post by Lethargeek »

PeterJ wrote:
Sat Jul 04, 2020 7:21 pm
Thank you for pointing me in the right direction @MatGubbins, but not giving me the answer. That is a great way to learn. I was clearing the attribute memory, rather than the pixel memory!

Code: Select all

clsscr              
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret

Code: Select all

clsscr              
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),l
    ldir
    ret
2 x

XoRRoX
Dizzy
Posts: 52
Joined: Wed Jul 11, 2018 6:34 am

Re: Help with attributes and logical and (z80 assembler)

Post by XoRRoX »

Lethargeek wrote:
Sun Jul 05, 2020 10:20 am

Code: Select all

clsscr              
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),l
    ldir
    ret
Smart. I realised that this will make more sense when numbers are used in hex.
0 x

User avatar
Guesser
Microbot
Posts: 179
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: Help with attributes and logical and (z80 assembler)

Post by Guesser »

utz wrote:
Sat Jul 04, 2020 7:48 pm
That's one reason why I prefer using hexadecimal numbers: They're easier to translate into binary. And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/
That's jolly addictive. I got my high score up to 39 before the arm cramp stopped me playing more.
0 x

Post Reply