Skip to content

Commit

Permalink
Add register 0x04 for device commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markadev committed Jan 13, 2024
1 parent e23906f commit f6e3463
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
37 changes: 35 additions & 2 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ When enabled this will:
"Colors" originally created by NTSC artifacting will appear as sequences of dots.
* Switch to the monochrome color palette (black & white by default)

This setting will be saved across power-cycles if the "Save" command is executed.


## Device Registers

The card's device registers can be written to change some settings. *These settings are
not saved between power-cycles*
The card's device registers can be written to change some settings. These settings persist across
CPU resets and will be saved permanently if the "Save" command is executed (see register 4).

The register base address depends on the slot number in which you installed the card:

Expand Down Expand Up @@ -92,3 +94,34 @@ For example, to replace the '#' character (character number `$A3`) with '£':
POKE BASEADDR+3, 132
POKE BASEADDR+3, 250
POKE BASEADDR+3, 128

Changes made to the text character patterns will be saved permanently when the "Save" command
is executed.


### Register 4 - Device command

**[write-only]**
This register allows a one-shot device command to be executed. The value written is the command
to execute.

| value | Description
| --------- | -----------
| $00 | Load the default configuration values
| $01 | Load the stored configuration from flash. This automatically happens on power-up.
| $02 | Save the current configuration to flash



#### Saving settings permanently

To permanently save changes to flash, like say you update a text character pattern or want to always
have scanline emulation enabled, then you just execute command `$02`:

POKE BASEADDR+4, 2

To permanently restore the default settings (text font, monochrome colors, etc) you would need to execute
command `$00` to revert the RAM settings to the defaults and then `$02` to save the change to flash:

POKE BASEADDR+4, 0
POKE BASEADDR+4, 2
34 changes: 34 additions & 0 deletions pico/device_regs.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "device_regs.h"

#include <string.h>
#include "buffers.h"
#include "colors.h"
#include "config.h"
#include "textfont.h"


static unsigned int char_write_offset;
Expand Down Expand Up @@ -38,6 +41,37 @@ void device_write(uint_fast8_t reg, uint_fast8_t data) {
char_write_offset = (char_write_offset + 1) % sizeof(character_rom);
break;

// device command
case 0x04:
execute_device_command(data);
break;

default:;
}
}


// Handle a write to the "command" register to perform some one-shot action based on the
// command value.
//
// Note: some of these commands could take a long time (relative to 6502 bus cycles) so
// some bus activity may be missed. Other projects like the Analog-V2 delegate this execution
// to the other (VGA) core to avoid this. Maybe do this if the missed bus cycles become a noticable
// issue; I only expect it would happen when some config is being saved, which is not done often.
void execute_device_command(uint_fast8_t cmd) {
switch(cmd) {
case 0x00:
// reset to the default configuration
config_load_defaults();
break;
case 0x01:
// reset to the saved configuration
config_load();
break;
case 0x02:
// save the current configuration
config_save();
break;
default:;
}
}
1 change: 1 addition & 0 deletions pico/device_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include <stdint.h>

extern void device_write(uint_fast8_t reg, uint_fast8_t data);
extern void execute_device_command(uint_fast8_t cmd);

0 comments on commit f6e3463

Please sign in to comment.