Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve palette on DLOAD call under cpc #1035

Open
poppichicken opened this issue Nov 18, 2024 · 8 comments
Open

Preserve palette on DLOAD call under cpc #1035

poppichicken opened this issue Nov 18, 2024 · 8 comments
Labels
-done- Done cpc Amstrad CPC 664 enhancement New feature or request
Milestone

Comments

@poppichicken
Copy link

hi Marco.

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

DLOAD "data.txt" TO 8000h SIZE 8
PRINT "END"

This seems to cause the CPC to crash.
After changing the border to WHITE and the background to BLACK, the whole screen (including border) changes to BLUE and nothing is printed.

@spotlessmind1975 spotlessmind1975 changed the title DLOAD (CPC) Crash after using DLOAD on a specific memory location Nov 18, 2024
@spotlessmind1975 spotlessmind1975 added wontfix This will not be worked on documentation Improvements or additions to documentation labels Nov 18, 2024
@spotlessmind1975
Copy link
Owner

Hi @poppichicken , and thank you for your bug report!

This program cannot work because the memory at hexadecimal location &H8000 is not necessarily writable, free, or able to contain data. Loading data into that location may cause undefined behavior, such as the one you describe.

To be sure that the operation is feasible, you need to use ugBASIC to reserve the space where you will write. For example, if you need to load 8 characters, you can define an array of 8 elements of type BYTE and use the VARPTR function to obtain its address:

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

DIM spare(8) AS BYTE

DLOAD "data.txt" TO VARPTR(spare) SIZE 8
PRINT "END"

In other way, you can define an 8-character dynamic string, and finally use the STRPTR function:

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

spare = SPACE(8)

DLOAD "data.txt" TO STRPTR(spare) SIZE 8
PRINT "END"

Thank you again!

@poppichicken
Copy link
Author

poppichicken commented Nov 19, 2024

Thanks Marco.
That makes sense.

DIM spare(8) AS BYTE
PRINT "BEFORE"
DLOAD "data.txt" TO VARPTR(spare) SIZE 8
PRINT "AFTER"

However the above code doesn't work.
It prints "BEFORE" and then seems to keep reprinting it.

image

Using STRPTR does the same thing.

spare = SPACE(8)
PRINT "BEFORE"
DLOAD "data.txt" TO STRPTR(spare) SIZE 8
PRINT "AFTER"

"data.txt" contains this:

12345678

@spotlessmind1975
Copy link
Owner

Hi @poppichicken , thank you for the feedback!

I am sorry, my mistake, I forgot that it is necessary to define a storage on which you will then operate. In fact, DLOAD loads a file dynamically from the disk. The disk, however, is built by ugBASIC. It is therefore necessary to tell ugBASIC that the file must be inserted into the disk. This can be done with the BEGIN STORAGE and ENDSTORAGE commands.

This is a program that works:

BEGIN STORAGE "disk1"
    FILE "data.txt"
ENDSTORAGE

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

spare = SPACE(8)

DLOAD "data.txt" TO STRPTR(spare) SIZE 8
PRINT spare
PRINT "END"

Alternatively, it is necessary to take the file with the disk, in which the compiled executable will have been inserted, and insert the file into the disk later, before running it

Thank you again!

@poppichicken
Copy link
Author

Excellent!
It does indeed work.

BEGIN STORAGE "disk1"
    FILE "data.txt"
ENDSTORAGE

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

spare = SPACE(8)
DLOAD "data.txt" TO STRPTR(spare) SIZE 8
PRINT spare

PRINT "END"

However, something odd happens.
When it first runs, the screen goes black and the border goes "white", as expected.

Then the entire screen goes blue, which looks a bit like the program has crashed.
But then suddenly the contents of the text file are printed, so that part has worked.
It's just the way the screen colours are changed that is a concern.

image

@spotlessmind1975
Copy link
Owner

Hi @poppichicken , and thank you for the feedback!

From my recollections of the first implementation, this is a side effect of the use of system routines (ROM). These reset the screen colors to a default value during the interrupt that is responsible for responding to hardware (disk drive) input. If there was a way to know which memory locations the computer's operating system reads to populate these two colors (border and background, but also palette), this problem could be solved. Unfortunately, I couldn't find them in documentations.

Let me know if you have any way to find them.

Thank you!

@poppichicken
Copy link
Author

poppichicken commented Nov 20, 2024

Ah yes of course, that makes sense.
I don't think it's a problem at all, as it can be worked around by changing screen settings after the DLOAD command.

BEGIN STORAGE "disk1"
    FILE "data.txt"
ENDSTORAGE

spare = SPACE(8)
DLOAD "data.txt" TO STRPTR(spare) SIZE 8

BITMAP ENABLE(160,200,16)
BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

PRINT spare
PRINT "END"

image

@spotlessmind1975 spotlessmind1975 changed the title Crash after using DLOAD on a specific memory location Preserve palette on DLOAD call under cpc Nov 20, 2024
@spotlessmind1975 spotlessmind1975 added the cpc Amstrad CPC 664 label Nov 20, 2024
@spotlessmind1975 spotlessmind1975 added this to the future milestone Nov 20, 2024
@spotlessmind1975
Copy link
Owner

Hi @poppichicken, absolutely yes, the workaround is valid. However, it would be nice to be able to fix this "smudge". For this reason, I changed the title of this ticket, I reopened it and promoted it to an improvement.

@poppichicken
Copy link
Author

Thanks Marco.

@spotlessmind1975 spotlessmind1975 added enhancement New feature or request and removed documentation Improvements or additions to documentation wontfix This will not be worked on labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-done- Done cpc Amstrad CPC 664 enhancement New feature or request
Projects
Status: In progress
Development

No branches or pull requests

2 participants