|
Post by 8bitheaven on Apr 16, 2016 14:53:30 GMT
I am looking for a little help in using Peeks and Pokes in a Basic program. I used Basic 8 to create three programs to graphically display data for Blood pressure/Sugar monitor and Local Temperature. In all three programs I use a small subroutine to display averages to one decimal place. In the Programmers Programming Reference manual there are several locations that reference positions after the decimal point. How do I use Peeks and Pokes to set this to one decimal place? any help would be appreciated. Long live the 128
|
|
|
Post by hydrophilic on Apr 17, 2016 3:37:12 GMT
What is "Peeks and Pokes"? I understand general concept, and have created many web pages about Poking (or Peeking) the RAM of C128, but I don't understand you specific post/question... If you simply want to DISPLAY a value with 1 decimal point, then use something like this: 100 X=1.2345 110 PRINT USING "#.#"; X
(Note that example will display 1.2) The same code will also "round up", for example... 100 X=3.4567 110 PRINT USING "#.#; X
(Note that example will display 3.5) ... There are many things you can do with PRINT USING... I hope this post answers your question(s)... [if not, see also my BASIC Encyclopedia entry for USING]
The other option is to use old/classic BASIC command (print), but then you must "manually" round your value... this would require a lot of math to explain, but if you want to know, just ask, and I (or another member) will give an answer...
|
|
|
Post by 8bitheaven on Apr 17, 2016 15:37:41 GMT
Thanks for your help but Basic 8 does not support the use of Print Using or Print to display numbers. The subroutine that I use to limit the data to 1 decimal place does a good job of this. However if I could use the Poke command to change all data to to 1 decimal place I could delete the subroutine. The Programmers Reference Guide Lists two locations that reference the number of decimals after the decimal point. Page # 504 memory location 005F and Page 510 memory location 012D. Thanks again for youe help.
|
|
|
Post by gsteemso on Apr 19, 2016 2:06:05 GMT
I feel you may be labouring under a misconception here. Commodore BASIC does not store numbers in decimal form internally. Any concept of "numbers have x decimal places" inherently applies ONLY to the display of those numbers, not how they are stored or how calculations are performed using them.
That said, in theory you could mutilate the internals of BASIC such that any and all conversions from floating-point to character-string values automatically only show one decimal place. If that possibility was actively allowed for when the ROMs were laid out, it is entirely plausible that the number of digits to place after the decimal point is stored as an ordinarily unchanging, but editable, variable in RAM somewhere; which could easily be altered in that way by a simple POKE command. Is that what you meant?
|
|
|
Post by 8bitheaven on Apr 19, 2016 12:27:28 GMT
Thanks for your input. I do know that Basic does not store numbers in decimal form. If I could poke a value in ram that controls the digits after the decimal point that is what I need. Thanks again.
|
|
|
Post by gsteemso on Apr 19, 2016 13:07:55 GMT
Ah, so you did already know that, that's good. I hope I didn't come across as patronizing, there! You did mention a couple of memory locations which a book claims to be relevant, so I suppose the easiest way forward is as follows:
1) in direct mode, tell BASIC to PRINT a decimal number and manually count how many digits show up after the period. That will give you a baseline: Now you will know approximately what value should already be in the memory location you're looking for.
2) examine each of the candidate locations (whether by PEEK or via the built-in machine language monitor, user's choice), in hopes of seeing either the value determined in step 1 or a number that only differs from it by 1.
3) if you found it, POKE a (smaller!) test value into it and then repeat the PRINT test to verify. If you didn't find it, well, I can think of a few things to try but none of them seem especially likely to work (I am not very experienced at this sort of blind "code archaeology"—much of my relevant knowledge comes from reading about others' successes).
|
|
|
Post by 8bitheaven on Apr 21, 2016 16:20:38 GMT
Thanks for the advice. I tried your suggestion but it did nothing. I tried it at both memory locations. It seems that this should be easier than this. I may just use the subroutine. Thanks.
|
|