Howto paint a squared zone of the screen ?

2»

Comments

  • edited June 2010
    Yes, I've made a few simple games in asm in 1990s. They were bad. In 2000s I only made some utilites, and also helped other people to make their games.

    To get result from the basic you need to place it into BC register. So, you need to do this:
    .loop1
    	cp 13			;if 'enter' key
      ld a,(cursor)
      ld b,0
      ld c,a
    	ret z			;return from the menu
    	jr checkKeys	;some other key, ignore and continue
    

    And you'll get cursor row number as result of USR function.
  • edited June 2010
    Instead of loading ATTR addresses with fixed values ( LD (HL),A ) you might XOR the the ATTRs: LD A,n, XOR A,(HL), LD (HL),A. This will remove the need
    for some jp's.
    Now I was quietly waiting, but curiousity has got the better of me: who's name will be on the program when it is finished?
  • edited June 2010
    the program is to be a menu game selection for my spectrum compilations.
    in fact i made it in basic but.. not enough quality because the speed.
    And by the way i always wanted to learn the Spectrum assembler. so never is late !!!
  • edited June 2010
    i dont understood to return data to the basic.
    What to do to return for example the text in the row when we use the enter key ? just to test if all works fine.
  • edited June 2010
    You can't return text, you only can return 16-bit number from machine code. However, the number can be an address of the text string, and then you can get the string using a number of PEEKs. However, this will require some more code.

    If you can't undestand how to return something at all, try this:
    ld bc,some number
     ret
    

    and call it using PRINT USR. You also can call it LET variable=USR, so instead of printing the value you'll get it into integer variable and can use later.

    In case with text string it will be something like this:
    ld bc,string
     ret
    string
     db "bla",0
    

    You'll get address of the 'b' letter in the memory, and will have to read all the letters in a loop, until you read 0 (end of the string). Something like this:
    10 LET a=USR ..
    20 LET c=PEEK a
    30 IF c==0 THEN STOP
    40 PRINT CHR$ c;
    50 LET a=a+1
    60 GO TO 20
    
  • edited June 2010
    where '10 LET a=USR ..' contains the address of what part of the memory ?
  • edited June 2010
    The address of your machine code, of course.

    Seems that SPIN built-in assembler does rather bad job as education tool, if you even don't know where your code is located and how to run it from BASIC. It is the very first things to learn.
  • edited June 2010
    ok but this address cause that the routine is executed twice. I mean the menu routine

    also
    checkKeys
     bit 5,(iy+1) ;waiting for a key, we get it in A
     jr z,checkKeys
     ld a,(23560)
     res 5,(iy+1)
    

    can you comment these lines ? for example the 23560
  • edited June 2010
    arfgh wrote: »
    You know what guys ? i begin to love this languaje. Cant understand why not put more effort on the 80's to learn it :( because it is really speedy.
    You're not putting in any effort now, you just want all the code written for you...
    I wanna tell you a story 'bout a woman I know...
  • edited June 2010
    false karingal. But is hard to start with the assembler. Or you know about someone that started faster with this language ?
  • edited June 2010
    The routine can be only executed twice if you call it twice, or if there is some bug in code (should be not).

    In the lines there is the keyboard polling using ROM routines. It involves two variables (iy+1=23611) updated with default IM1 interrupt handler. The handler polls the keyboard ports and generate ASCII code if some key is pressed. The code goes into 23560, and keypress signaled by bit 5 of 23611. It is the sort of knowledge you have to learn and memorize if you want to use ROM routines.
  • edited June 2010
    arfgh wrote: »
    false karingal. But is hard to start with the assembler. Or you know about someone that started faster with this language ?

    the mistake you're making is running before you can walk. Download one of the many good books on machine code and work through it in order so you understand the basics first.
  • edited June 2010
    guesser, could be, but i am learning a lot with codes as for example the shiru's ones.
  • edited June 2010
    ROM routine can't be in 23560, because this address in the RAM. It is a system variable. I've already posted link to a section of the BASIC manual with list of all the system variables.
  • edited June 2010
    arfgh wrote: »
    false karingal. But is hard to start with the assembler. Or you know about someone that started faster with this language ?
    Yes, most people.

    Try downloading these books, read them and work through the examples contained within before you go any further.

    ftp://ftp.worldofspectrum.org/pub/sinclair/books/MasteringMachineCodeOnYourZXSpectrum.pdf

    ftp://ftp.worldofspectrum.org/pub/sinclair/books/SpectrumMachineLanguageForTheAbsoluteBeginner.pdf

    ftp://ftp.worldofspectrum.org/pub/sinclair/books/ProgrammingTheZ80_2ndEdition.pdf
    I wanna tell you a story 'bout a woman I know...
  • edited June 2010
    Yes karingal, but, first problem. I am not English and my understanding of the language is very limited. For this reasson is always hard to start. But thx for these books.

    Well shiru i used a bit the debugger and then i see how the BC contains the row number on the menu selection when the enter key is used. Then, the code end and return to the basic just to execute the follow basic:

    10 let a=usr 32768
    20 let b=peek a
    30 print b
    and the result was '242' I expected the row line number as is into the BC registers

    of course i did something bad as usual... but what
  • edited June 2010
    Of course your code does not work, because row number is not address of the string. To get the address of the string you need more code, to calculate it from the row number.

    Replace 'ret z' with jr z,returnAdr and add this code before menuItems:
    returnAdr
     ld a,(cursor)
     inc a
     ld e,a
     ld hl,menuItems
     ld b,h
     ld c,l
    .loop0
     ld a,(hl)
     inc hl
     or a
     jr z,.loop1
     cp #ff
     jr z,.loop1
     jr .loop0
    .loop1
     dec e
     ret z
     ld b,h
     ld c,l
     jr .loop0
    

    Don't forget that the strings can have either 0 and 255 as end of string code.
  • edited June 2010
    arfgh wrote: »
    Yes karingal, but, first problem. I am not English and my understanding of the language is very limited. For this reasson is always hard to start. But thx for these books.
    *gives up*
    I wanna tell you a story 'bout a woman I know...
  • edited June 2010
    Shiru. First you said some replies ago that to obtain in the basic the row number line on the menu, we must use the follow code:
    loop6
     cp 13 ;if 'enter' key
     ld a,(cursor)
     ld b,0
     ld c,a
     ret z
     jr checkKeys ;some other key, ignore and continue
    

    then we can do the follow in basic to obtain the row number:

    10 let a=usr 32768
    20 let b = peek a
    30 print b

    But this dont works. Using the follow code worked:
    loop6
     cp 13 ;if 'enter' key
     ld bc,cursor
     ret z
     jr checkKeys ;some other key, ignore and continue
    
  • edited June 2010
    All my code here is tested and debugged, it is working. I've already said why your code will not work, in the first sentence of #40. It is your mistake in your BASIC code, and you really should think at least for some, if you want to learn anything.

    'Follow code' will work indeed, with your wrong BASIC code only, and if you think some more, you'll figure out why.
  • edited June 2010
    Sounds like you got your code working there in the end there arfgh... Perhaps you wouldn't mind therefore reposting the source code with all the edits included along with the BASIC header, for the benefit of other beginners, and perhaps also to confirm to Shiru and others that you understood and got it... I for one might find this helpful...

    ..Iv been following this thread with some interest, and want to say thankyou to Shiru and others for their patience and contributions... Its been an interesting exercise...

    I gather now, that you understand the confusion between what your code was doing previously (BC holding only one byte), and what Shiru was trying to suggest (BC holding a 2 byte referrence address) and why your BASIC needed adjusting for the extra source edits?...
  • edited June 2010
    kgmcneil, sorry but i dont understood very well in the last reply.
    Yes, just doing the modification i said in my previous reply, i can obtain the menu line number that was selected with the enter key. The result come to the BC register.

    I dont understood what shiru said related to this.
  • edited June 2010
    KGMcneil I'll reiterate my advice that I gave to the OP here - Try ZX BASIC compiler (www.zxbasic.net).

    Over the past 12 months, I've been really getting my head around z80 assembler, purely because I wanted some library routines to make some features go faster.

    You can start programming in Sinclair Basic (almost), and have the compiler turn your basic into machine code. You can then slowly move to more advanced coding, moving to a more advanced freebasic like syntax.

    And if you want, you can start adding in little assembler routines very easily indeed....

    and as you do that, you learn assembler, within assembler.

    Also, looking at the code library over on the wiki there might not be a bad idea either. I've tried to make it all documented.

    In short, I think it's a viable path to go from being someone who can write BASIC to someone who can work in assembler.
  • edited June 2010
    Good advice... Iv actually been tinkering with your ZX Basic compiler now for sometime... ;) ...I have it set up with scripts to automatically turn BASIC listing into autorunning .TAP's of compiled machine code compressed using Megalz... Quite handy really! (Hmmmm..maybe I could make some more savings using bin2rem...?)... Iv been regularly updating my files each time you release an update, and do check the forums every now and again... I haven't contributed much, beyond the occasional entry on the wishlist, partly because much of what is discussed is way out of my league!!!!... Nevertheless, Iv learned plenty already, just from reading the code examples often posted there...

    Im looking forward to seeing LCD's IDE...

    Most of my projects (tools mainly) so far have been in other languages, using only the occasional bit of assembly... However, I do tend to like to prototype ideas and find BASIC ideal for this... And what I lack in speed when prototyping, I can make up for by hitting compile...

    Iv even been known to test ideas out for other systems using speccy basic... which I can then compile, and run through an emulator on full speed, if I need to...

    ..so, you see, as I once said, your project does get used... its just that many of the people using your tool are probably invisible on the forums...

    Thanks again, for creating such a useful tool!
  • edited June 2010
    kgmcneil wrote: »
    Thanks again, for creating such a useful tool!

    I'd like to say you're welcome...but 99% of the heavy lifting has been done by Boriel!

    It's almost all his baby. I've just been pipping in with suggestions here and there; (and lots of "I'm an idiot" things too) and LCD has been putting together what we're hoping is an awesome IDE for it.
  • edited June 2010
    Gedlion

    i tried thsi compiler. But several things are not the same as in the Spectrum Basic. For this reasson i preferred to learn a bit of Z80 ASM
  • edited June 2010
    arfgh wrote: »
    Gedlion

    i tried thsi compiler. But several things are not the same as in the Spectrum Basic. For this reasson i preferred to learn a bit of Z80 ASM


    Well, I'm glad you tried it - though I'm a bit baffled by the logic of "it's not the same as Sinclair Basic, so I'll use something vastly different instead!"

    *chuckle*

    It was just a thought. I personally think it makes a good stepping stone from basic to assembler.
  • edited June 2010
    Also, learning proper, structured BASIC syntax (which ZX Basic uses) is highly recommended as it will let you get the hang with different compilers in the future.
Sign In or Register to comment.