├── README.md ├── doc ├── CompleteSpectrumROMDisassemblyThe.pdf ├── ZX Spectrum 48K ROM Original Disassembly.asm └── table_spectrum_characterset.png ├── images ├── b0p0.png ├── b1p1.png ├── b7p7.png └── new_vs_classic.png ├── prettybasic.asm └── prettybasic.rom /README.md: -------------------------------------------------------------------------------- 1 | prettybasic 2 | # ZX Spectrum 1982 ROM with syntax highlighting 3 | 4 | ![BORDER 7: PAPER 7](https://raw.githubusercontent.com/reclaimed/prettybasic/master/images/b7p7.png) 5 | 6 | ### What's it? 7 | An extended ZX Spectrum 48K ROM with syntax highlighting and basic formatting. 8 | 9 | Color groups: 10 | * letters 11 | * digits 12 | * functions 13 | * operators 14 | * flow operators (GO TO, GO SUB...RETURN, IF...THEN, FOR...NEXT) 15 | * REM and its content 16 | 17 | Formatting: 18 | * colon (:) is now acting as a carriage return 19 | * IF...THEN is multiline 20 | 21 | Misc.: 22 | * control codes (ASCII 00...31) are now hidden in the LIST mode (and HAVE to be shown in edit mode (CS+1), but they're not) 23 | * contrast-aware dynamic palette 24 | 25 | Bugs and todo: 26 | * line numbers are being printed in the current INK color - there is a separate subroutine that prints the line numbers 27 | * control codes (ASCII 00...31) must be visible in edit mode 28 | 29 | 30 | ### But... why? 31 | Mostly to read the old BASIC games. They were written in the infamous style "squeeze everything in 9999 lines" and quite hard to read due to it. Below are examples compared side by side: 32 | 33 | ![NEW vs CLASSIC](https://raw.githubusercontent.com/reclaimed/prettybasic/master/images/new_vs_classic.png) 34 | 35 | ### Behind the scenes 36 | * The modification is based on the [disassembly](http://www.worldofspectrum.org/infoseekid.cgi?id=2000076) done by Dr Ian Logan & Dr Frank O’Hara 37 | * The original procedure at the address 0x1937 was replaced with a new one 0x386E 38 | * [Zeus Z80 Assembler](http://www.desdes.com/products/oldfiles/zeus.htm) 39 | 40 | ### Dynamic palette 41 | Colors schemes are being calculated dynamically based on the value of PAPER, as this pseudocode is illustrating: 42 | ```pseudocodess 43 | # address of the system register containing the current color 44 | const uint16 ATTR_T = 23695 45 | 46 | uint8 current_color 47 | uint8 original_color 48 | uint8 paper_color 49 | 50 | function set_color(byte modifier){ 51 | current_color = PEEK(ATTR_T) 52 | original_color = current_color 53 | paper_color = bit_extract(current_color, 3-5) 54 | paper_color = bit_right_shift(paper_color, 3) 55 | current_color = current_color AND b11111000 AND paper_color XOR modifier 56 | POKE (ATTR_T), current_color 57 | } 58 | 59 | function restore_color(){ 60 | POKE (ATTR_T), original_color 61 | } 62 | ``` 63 | ### ATTR T description 64 | 65 | "ATTR T" is a [system register](http://www.worldofspectrum.org/ZXBasicManual/zxmanchap25.html) containing the value of the color attribute to be written into the VRAM attribute area. 66 | 67 | The system registers are basically the bytes in the RAM, and "ATTR T" has fixed address of 0x5C8F (decimal 23695). 68 | 69 | ROM screen output routines are seemingly using "ATTR T" each time a character or a graphical primitive is to be drawn, thus writing in 0x5C8F is the fastest way to set the output color. 70 | 71 | ``` 72 | Address: 0x5C8F 73 | 74 | #bit description 75 | 0 ink blue 76 | 1 ink red 77 | 2 ink green 78 | 3 paper blue 79 | 4 paper red 80 | 5 paper green 81 | 6 bright 82 | 7 flash 83 | ``` 84 | 85 | Examples of the dynamic palette: 86 | 87 | ![BORDER 7: PAPER 7](https://raw.githubusercontent.com/reclaimed/prettybasic/master/images/b7p7.png) 88 | 89 | ![BORDER 0: PAPER 0](https://raw.githubusercontent.com/reclaimed/prettybasic/master/images/b0p0.png) 90 | 91 | ![BORDER 1: PAPER 1](https://raw.githubusercontent.com/reclaimed/prettybasic/master/images/b1p1.png) 92 | 93 | ### Legal status 94 | 95 | ZX Spectrum and its firmware (ROM) are owned by AMSTRAD and their position on this matter is quite liberal: 96 | * Users allowed to change the firmware if they want to 97 | * Users allowed to distribute the ROM modified or not, as soon as it contains the original copyright message 98 | * No one is allowed to sell the ROM, doesn't matter how many time and efforts they invested in modifications 99 | * Whoever is distributing the ROM as a part of the illegal hardware, "nailing them up by the testicles using rusty nails" is strongly recommended (lol they have a whole Eastern Block of nails to rust) 100 | * However, authors of emulators are allowed to charge customers for the code they produced (i.e. the emulator) even if the ROM included into distribution 101 | 102 | 103 | ### Thanks for help to 104 | 105 | * Guys from the forum http://zx-pk.ru : 106 | * weiv 107 | * AndTorp 108 | * iceoflame 109 | * Andrew771 110 | * Alex Rider 111 | * [Andrew Owen](https://github.com/cheveron/) 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /doc/CompleteSpectrumROMDisassemblyThe.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/doc/CompleteSpectrumROMDisassemblyThe.pdf -------------------------------------------------------------------------------- /doc/table_spectrum_characterset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/doc/table_spectrum_characterset.png -------------------------------------------------------------------------------- /images/b0p0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/images/b0p0.png -------------------------------------------------------------------------------- /images/b1p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/images/b1p1.png -------------------------------------------------------------------------------- /images/b7p7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/images/b7p7.png -------------------------------------------------------------------------------- /images/new_vs_classic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/images/new_vs_classic.png -------------------------------------------------------------------------------- /prettybasic.rom: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reclaimed/prettybasic/f0b859ff0daff0dc26673ade1fd29bc6b7d3d292/prettybasic.rom --------------------------------------------------------------------------------