CPCWiki forum

General Category => Programming => Topic started by: mr_lou on 18:55, 19 October 18

Title: Turn this into an RSX
Post by: mr_lou on 18:55, 19 October 18
Can someone help me turn the following into an RSX command?

10 FOR a=1 TO 17:POKE 39999+a,VAL("&"+MID$("DD7E00CDB4BBF5CD60BB320000F1C3B4BB",a*2-1,2)):NEXT

20 LOCATE x,y:CALL 40000,0:PRINT CHR$(PEEK(0)) '  this works as COPYCHR$ in any CPC


Instead of line 20 I could like to be able to instead go: |code,x,y or |ascii,x,y and get back the ASCII character code - not the actual CHR$ of the ASCII code.
In other words, I want an RSX command that'll return the ASCII code of the character on the screen at location x,y.

Thanks!
Title: Re: Turn this into an RSX
Post by: mr_lou on 19:05, 19 October 18
I should probably add that I still need everything to be done as in line 10. I.e. all from BASIC. No loading on any binary file, and no ASM source.  :)
Title: Re: Turn this into an RSX
Post by: AMSDOS on 00:25, 20 October 18
Quote from: mr_lou on 18:55, 19 October 18
Can someone help me turn the following into an RSX command?

10 FOR a=1 TO 17:POKE 39999+a,VAL("&"+MID$("DD7E00CDB4BBF5CD60BB320000F1C3B4BB",a*2-1,2)):NEXT

20 LOCATE x,y:CALL 40000,0:PRINT CHR$(PEEK(0)) '  this works as COPYCHR$ in any CPC


Instead of line 20 I could like to be able to instead go: |code,x,y or |ascii,x,y and get back the ASCII character code - not the actual CHR$ of the ASCII code.
In other words, I want an RSX command that'll return the ASCII code of the character on the screen at location x,y.

Thanks!


This is what I came up with, it uses a routine which is on the Wiki (http://www.cpcwiki.eu/index.php/Programming:Display_a_byte_as_a_3-digit_decimal_number) to print a 3 digit decimal number



10 p=1:FOR a=&A000 TO &A046:POKE a,VAL("&"+MID$("210FA0010AA0CDD1BCC913A0C319A0FCA60AA041534349C900DD6E00DD6602CD75BBCD60BBCD29A0C90664CD35A0060ACD35A006010E009038030C18FA80F579C630CD5ABBF1C9",p,2):p=p+2:NEXT a:CALL &A000



To use |ASCII,x,y and it will print the value at that position.
Title: Re: Turn this into an RSX
Post by: mr_lou on 07:36, 20 October 18
Quote from: AMSDOS on 00:25, 20 October 18
This is what I came up with, it uses a routine which is on the Wiki (http://www.cpcwiki.eu/index.php/Programming:Display_a_byte_as_a_3-digit_decimal_number) to print a 3 digit decimal number
To use |ASCII,x,y and it will print the value at that position.

Thanks!

It does output a 3-digit number. But I am unable to put this number into a variable, like

a = |ascii,1,1
a$ = |ascii,1,1


Those just gives me a syntax error?
Title: Re: Turn this into an RSX
Post by: HAL6128 on 07:47, 20 October 18
Passing back a varable with a RSX should be able with @a (address)?


Should this function do the same as the Basic command ASC?
Title: Re: Turn this into an RSX
Post by: mr_lou on 08:33, 20 October 18
Quote from: HAL 6128 on 07:47, 20 October 18
Passing back a varable with a RSX should be able with @a (address)?


Should this function do the same as the Basic command ASC?
Yea, the idea was to be able to call |ascii,x,y to know which ascii code is currently visible on that location on the screen. And then be able to use that in game logic. I.e.
if |ascii,x,y = 239 then ...

EDIT: Hm, I realize RSX commands probably can't do that.....?
Title: Re: Turn this into an RSX
Post by: Urusergi on 17:04, 20 October 18
Quote from: HAL 6128 on 07:47, 20 October 18
Passing back a varable with a RSX should be able with @a (address)?

p=1:FOR a=&A000 TO &A02A:POKE a,VAL("&"+MID$("2109A0010DA0C3D1BC09A00DA012A0C318A041534349C900AFCDB4BBF5CD60BBDD6E00DD660177F1C3B4BB",p,2)):p=p+2:NEXT a:CALL &A000

Syntax:
a%=0:LOCATE x,y: |ASCII,@a%:PRINT a%
Title: Re: Turn this into an RSX
Post by: mr_lou on 17:09, 20 October 18
Quote from: Urusergi on 17:04, 20 October 18
p=1:FOR a=&A000 TO &A02A:POKE a,VAL("&"+MID$("2109A0010DA0C3D1BC09A00DA012A0C318A041534349C900AFCDB4BBF5CD60BBDD6E00DD660177F1C3B4BB",p,2)):p=p+2:NEXT a:CALL &A000

Syntax:
a%=0:LOCATE x,y: |ASCII,@a%:PRINT a%

I was just wondering about that exact syntax. Was just about to write a post asking about it. Except I'd prefer if the LOCATE command was also part of the RSX. (Wouldn't it speed things up a bit?)

So it becomes:
a%=0
|ascii,x,y,@a%
print a%


Or even better:
a%=0
|address,@a% ' Only need to be called once
|ascii,x,y
print a%


Title: Re: Turn this into an RSX
Post by: Urusergi on 21:45, 20 October 18
Quote from: mr_lou on 17:09, 20 October 18
I was just wondering about that exact syntax. Was just about to write a post asking about it. Except I'd prefer if the LOCATE command was also part of the RSX. (Wouldn't it speed things up a bit?)

Ok, here you are 8)
p=1:FOR a=&A000 TO &A02D:POKE a,VAL("&"+MID$("2109A0010DA0C3D1BCFCA60DA012A0C318A041534349C900AFCDB4BBF5DD6E02DD6604CD75BBCD60BB12F1C3B4BB",p,2)):p=p+2:NEXT a:CALL &A000

Syntax:
10 a%=0:x%=1:y%=1
20 |ASCII,x%,y%,@a%
30 PRINT a%


EDIT: And the other one:
p=1:FOR a=&A000 TO &A040:POKE a,VAL("&"+MID$("2109A0010DA0C3D1BCFCA60DA015A0C322A0C327A0414444524553D341534349C900ED5341A0C9AFCDB4BBF5DD6E00DD6602CD75BBCD60BBED5B41A012F1C3B4BB",p,2)):p=p+2:NEXT a:CALL &A000

Syntax:
10 a%=0:|ADDRESS,@a%
20 x%=1:y%=1:|ASCII,x%,y%
30 PRINT a%
Title: Re: Turn this into an RSX
Post by: AMSDOS on 22:33, 20 October 18

Quote from: mr_lou on 07:36, 20 October 18
Thanks!


It does output a 3-digit number. But I am unable to put this number into a variable, like


a = |ascii,1,1
a$ = |ascii,1,1



Those just gives me a syntax error?


There was no mention of a variable, only that you wanted to output the ASCII value on a character at location x,y, that's how I read it in your initial post.


QuoteExcept I'd prefer if the LOCATE command was also part of the RSX. (Wouldn't it speed things up a bit?)


Not necessarily, I had this discussion here (http://www.cpcwiki.eu/forum/programming/interesting-type-ins/msg111426/#msg111426) a couple of years ago, the outcome there was RSX routines were slower than the Tokenised BASIC. The situation changes when a program is compiled. There maybe some benefit from having a LOCATE incorporated with the TXT RD CHAR, though I think this is why some people choose to use CALL instead of a RSX.
Title: Re: Turn this into an RSX
Post by: funkheld on 20:03, 02 November 18

Hi good afternoon.


it is a waste of memory for the data.
first in a string and then again the data in another memory area.  >:(


bin from disk to memory.   ;D


greeting
Title: Re: Turn this into an RSX
Post by: AMSDOS on 21:35, 02 November 18
Quote from: funkheld on 20:03, 02 November 18
Hi good afternoon.


it is a waste of memory for the data.
first in a string and then again the data in another memory area.  >:(


bin from disk to memory.   ;D


greeting


That's just wasting Disk Space though  :D 


A BASIC Stub file is the most efficient, but it's a hassle writing a saver for it and is not so easy presenting a file to paste into an emulator and not good if that file is the subject of further editing.


Some foreign type-ins I've seen setup a REM statement at the start of a program and use that to store their M/C routine in that, again it would be double handling, though it would still be within the BASIC area. I think someone might have made a TXT RD CHAR (COPYCHR$) routine like that.
Title: Re: Turn this into an RSX
Post by: mr_lou on 21:41, 02 November 18
There can be reasons for not wanting a bin on disk.

For example, I believe the CPCretroDev BASIC competition requires your BASIC game to only be in one file - and only use BASIC.
Not sure if any RSX commands invalidates the game though.
Title: Re: Turn this into an RSX
Post by: AMSDOS on 23:30, 02 November 18
Quote from: mr_lou on 21:41, 02 November 18
There can be reasons for not wanting a bin on disk.

For example, I believe the CPCretroDev BASIC competition requires your BASIC game to only be in one file - and only use BASIC.
Not sure if any RSX commands invalidates the game though.


To only use BASIC means no M/C routines can be used, I don't know how far that can be taken though. In this case it's a standard routine to read the screen and return a character using the firmware, in order to make the game compatible with all the machines.


I have highlighted alternative BASIC methods which do take more time to work on, though the results have been satisfying, despite using up a bit more memory.


One of the games I submitted earlier this year to the 10-Liners Compo had a Sprite Driver in it. I explained that to them when I submitted the game, though they must of weight the game accordingly and decided to submit it into one of the regular categories. But it did seem somewhat dicey to be testing to see what's acceptable and what's not or where that line is drawn.



Powered by SMFPacks Menu Editor Mod