sd:getting_stuff_done_in_assembly_language
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sd:getting_stuff_done_in_assembly_language [2026/06/01 05:36] – appledog | sd:getting_stuff_done_in_assembly_language [2026/06/01 14:44] (current) – appledog | ||
|---|---|---|---|
| Line 123: | Line 123: | ||
| </ | </ | ||
| - | === Moving right along | + | === Random Numbers |
| - | We're not going to provide examples of other basic stuff too much, but we will show you this demo program | + | Random numbers are really useful. Here, we demonstrate the xorshift generator |
| <codify armasm> | <codify armasm> | ||
| + | ; Example 4: Random Numbers | ||
| + | |||
| .address $C000 | .address $C000 | ||
| Line 170: | Line 172: | ||
| ; ============================================================================ | ; ============================================================================ | ||
| - | ; AH=00h - Random Number | + | ; AH=00h - Random Number |
| ; Input: | ; Input: | ||
| - | ; Output: B = random 16-bit | + | ; Output: |
| - | ; Notes: | + | ; Notes: |
| - | ; | + | |
| ; ============================================================================ | ; ============================================================================ | ||
| Line 209: | Line 210: | ||
| <codify armasm> | <codify armasm> | ||
| + | ; Example 5: Menus and Colored Text | ||
| + | |||
| .address $C000 | .address $C000 | ||
| Line 222: | Line 225: | ||
| INT $10 | INT $10 | ||
| - | LDAH $50 | + | LDAH $50 ; Set teletype text default color |
| LDAL $2F ; color data in AL: BG=2, FG=F (here, orange) | LDAL $2F ; color data in AL: BG=2, FG=F (here, orange) | ||
| INT $10 | INT $10 | ||
| Line 230: | Line 233: | ||
| INT 0x05 | INT 0x05 | ||
| - | LDAH $50 | + | LDAH $50 ; Set teletype text default color |
| LDAL $29 ; color data default for mode 1 | LDAL $29 ; color data default for mode 1 | ||
| INT $10 | INT $10 | ||
| Line 270: | Line 273: | ||
| <codify armasm> | <codify armasm> | ||
| + | ; Example 6: The Cursor | ||
| + | |||
| .address $C000 | .address $C000 | ||
| Line 315: | Line 320: | ||
| RET ; return control to system. | RET ; return control to system. | ||
| + | </ | ||
| + | |||
| + | === Keeping Track Yourself | ||
| + | In a game, you don't really need the cursor. So instead of using a teletyle print function and calling INT $10, AH=$16, you can just give the values you want for your game screen. Here's an example of putting a character anywhere you want and using any color. Although it looks a bit trivial this ends up proving to be a very useful pattern. | ||
| + | |||
| + | <codify armasm> | ||
| + | ; Example 7: put_ccxy | ||
| + | |||
| + | .address $C000 | ||
| + | |||
| + | start: | ||
| + | LDX #0 | ||
| + | LDY #10 | ||
| + | LDC $03 | ||
| + | LDB #' | ||
| + | |||
| + | CALL @put_ccxy | ||
| + | RET | ||
| + | |||
| + | ; put_ccxy(B, X, Y, C) | ||
| + | ; Put Character and Color at X, T | ||
| + | ; INPUT: | ||
| + | ; B -- ascii code | ||
| + | ; X -- x location on screen | ||
| + | ; Y -- y location on screen | ||
| + | ; C -- hi nibble (BG) and low niblle (FG) | ||
| + | ; | ||
| + | put_ccxy: | ||
| + | ; Write character in AL at X, Y | ||
| + | LDAH $11 | ||
| + | INT $10 | ||
| + | |||
| + | ; Set color at X, Y | ||
| + | ; Input: | ||
| + | LDAH $13 | ||
| + | INT $10 | ||
| + | |||
| + | RET | ||
| </ | </ | ||
| Line 344: | Line 387: | ||
| <codify armasm> | <codify armasm> | ||
| + | ; Example 8: DEFCHAR | ||
| + | |||
| .address $C000 | .address $C000 | ||
| Line 367: | Line 412: | ||
| Unfortunately, | Unfortunately, | ||
| - | |||
| - | === put_ccxy | ||
| - | Let's make a combo function that puts a character and a color on the screen at the same time. We'll use the non-cursor version of these functions: | ||
| - | |||
| - | .address $C000 | ||
| - | |||
| - | start: | ||
| - | LDB #' | ||
| - | LDC $03 | ||
| - | LDX #39 | ||
| - | LDY #24 | ||
| - | |||
| - | CALL @put_ccxy | ||
| - | RET | ||
| - | |||
| - | ; put_ccxy(B, X, Y, C) | ||
| - | ; Put Character and Color at X, T | ||
| - | ; INPUT: | ||
| - | ; B -- ascii code | ||
| - | ; X -- x location on screen | ||
| - | ; Y -- y location on screen | ||
| - | ; C -- hi nibble (BG) and low niblle (FG) | ||
| - | ; | ||
| - | put_ccxy: | ||
| - | LDAH $11 ; Write character in B at X, Y | ||
| - | INT $10 | ||
| - | |||
| - | |||
| - | LDAH $13 ; Set color in C at X, Y | ||
| - | INT $10 | ||
| - | |||
| - | RET | ||
| - | </ | ||
| - | |||
| - | It's really a toss-up if you want to make two INT calls or just call put_ccxy. This is more about learning how those two functions can work. | ||
| === Using this concept in Mode 3 | === Using this concept in Mode 3 | ||
| Line 419: | Line 429: | ||
| <codify armasm> | <codify armasm> | ||
| + | ; Example 9: stamp_char | ||
| + | |||
| .address $C000 | .address $C000 | ||
| Line 509: | Line 521: | ||
| The way to do multicolor graphics is to use different tiles for each color component. For example, you can have one tile with the blue pixels and the other tile with the yellow pixels. When you draw the tiles on top of each other, it will produce a multicolor effect. | The way to do multicolor graphics is to use different tiles for each color component. For example, you can have one tile with the blue pixels and the other tile with the yellow pixels. When you draw the tiles on top of each other, it will produce a multicolor effect. | ||
| + | == Music | ||
| + | Randomly, in the middle of nowhere, we will explain to you; yes, you can play music in your game. Our PLAY statement is multi-voice; | ||
| + | |||
| + | <codify BASIC> | ||
| + | 10 PLAY "XV1 MN W5 XP3000 O4 L4 T180" | ||
| + | 15 PLAY "XV2 MN W5 XP3500 O3 L4 T180" | ||
| + | 20 PLAY "XV1 F1" | ||
| + | 25 PLAY "XV2 R1" | ||
| + | 30 PLAY "XV1 A4. B-8 > C4 C4 <" | ||
| + | 35 PLAY "XV2 R1" | ||
| + | 40 PLAY "XV1 B-4 A4 G4 F4" | ||
| + | 45 PLAY "XV2 R1" | ||
| + | 50 PLAY "XV1 > C2 C4. C8 <" | ||
| + | 55 PLAY "XV2 R2 F4. F8" | ||
| + | 60 PLAY "XV1 > C4 D2 C4 <" | ||
| + | 65 PLAY "XV2 F4 < B-2 A4" | ||
| + | 70 PLAY "XV1 B-4 A4 G4 G4" | ||
| + | 75 PLAY "XV2 B-4 F4 > C4 C4" | ||
| + | 80 PLAY "XV1 A1" | ||
| + | 85 PLAY "XV2 < F1" | ||
| + | </ | ||
| + | |||
| + | Now you may wonder, why incorporate a BASIC example? Here, we can use BASIC to quickly test musical ideas. When it's time to put them into a game, we do this: | ||
| + | |||
| + | <codify armasm> | ||
| + | ; Example 10: Music | ||
| + | |||
| + | .address $C000 | ||
| + | |||
| + | LDELM @fair_phyllis | ||
| + | LDAH $52 ; Play Song | ||
| + | INT $11 | ||
| + | RET | ||
| + | |||
| + | fair_phyllis: | ||
| + | .bytes "XV1 MN W5 XP3000 O4 L4 T180" | ||
| + | .bytes "XV2 MN W5 XP3500 O3 L4 T180" | ||
| + | .bytes "XV1 F1 " | ||
| + | .bytes "XV2 R1 " | ||
| + | .bytes "XV1 A4. B-8 > C4 C4 < " | ||
| + | .bytes "XV2 R1 " | ||
| + | .bytes "XV1 B-4 A4 G4 F4 " | ||
| + | .bytes "XV2 R1 " | ||
| + | .bytes "XV1 > C2 C4. C8 < " | ||
| + | .bytes "XV2 R2 F4. F8 " | ||
| + | .bytes "XV1 > C4 D2 C4 < " | ||
| + | .bytes "XV2 F4 < B-2 A4 " | ||
| + | .bytes "XV1 B-4 A4 G4 G4 " | ||
| + | .bytes "XV2 B-4 F4 > C4 C4 " | ||
| + | .bytes "XV1 A1 " | ||
| + | .bytes "XV2 < F1", 0 | ||
| + | </ | ||
sd/getting_stuff_done_in_assembly_language.1780292165.txt.gz · Last modified: by appledog
