Skip to content

Commit dde6427

Browse files
committed
calculate the reload value at compilation time in the Makefile
1 parent f98954e commit dde6427

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ EXECUTABLE = bootloader.bin
1515

1616
VIDEO_PATH = video.flv
1717

18+
FPS = $(shell ffmpeg -i $(VIDEO_PATH) 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p")
19+
RELOAD_VALUE = $(shell expr 1193182 / $(FPS))
20+
1821
ASCII_GRADIENT = oxxo
1922

2023
# targets
@@ -33,10 +36,9 @@ $(BUILD_DIR)/$(EXECUTABLE): $(BUILD_DIR)/code.bin $(BUILD_DIR)/data.bin
3336
$(BUILD_DIR)/code.bin: $(SOURCES)
3437
mkdir -p $(BUILD_DIR)
3538

36-
$(AS) $(ASFLAGS) $< -o $@
39+
$(AS) $(ASFLAGS) -DPIT_RELOAD_VALUE=$(RELOAD_VALUE) $< -o $@
3740

3841
$(BUILD_DIR)/data.bin: $(VIDEO_PATH)
3942
mkdir -p $(BUILD_DIR)
4043

41-
$(PYTHON) $(SRC_DIR)/converter/main.py $< -o $@ \
42-
--gradient $(ASCII_GRADIENT)
44+
$(PYTHON) $(SRC_DIR)/converter/main.py --gradient $(ASCII_GRADIENT) $< -o $@

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ To build the bootloader in the easiest way, just follow the instructions below.
1010
You can do it the manual way with an assembler, a video to ASCII converter and a virtualization software of your choice too, but then, you're on your own.
1111

1212
### Installing dependencies
13-
For Windows, you can install [`scoop`](https://scoop.sh/) and run:
13+
For Windows, you can install [Scoop](https://scoop.sh/) and run:
1414
```powershell
15-
scoop install nasm make python
15+
scoop install nasm make ffmpeg python
1616
```
1717

1818
As for Linux, all of the packages should be in your default package manager. Here's an example for Ubuntu:
1919
```bash
20-
sudo apt install nasm make python3
20+
sudo apt install nasm make ffmpeg python3
2121
```
2222

2323
If you want to run the bootloader, you need to install QEMU as well, which can be done with either `scoop install qemu` or `sudo apt install qemu`, depending on your operating system.
2424

25-
Once you have Python installed, you will also need to install the dependencies for the `vid2data` converter. Simply do:
25+
Once you have Python installed, you will also need to install the dependencies for the ASCII converter. Simply do:
2626
```bash
2727
python3 -m pip install -r src/vid2data/requirements.txt
2828
```
@@ -46,13 +46,8 @@ By default, the Makefile uses KVM as an accelerator for QEMU. Since KVM is exclu
4646
#### It's too slow/fast and/or the frame rate is unstable!
4747
~~In the future, I might implement something bigger, like a custom interrupt handler, to get a stable frame rate.~~
4848

49-
After like a month or maybe even more, I finally understood how to set up the PIT and add a handler in the IVT, thus, the framerate is now fully faithful to the original! If it's still going too slow/fast though, you might need to adjust the `PIT_RELOAD_VALUE` value on line 2 in [`src/pit.asm`](src/pit.asm).
50-
51-
To calculate the reload value, simply use the equation:
52-
```
53-
Reload Value = floor(1193182 / FPS)
54-
```
55-
where `FPS` is the framerate of the original video.
49+
After like a month or maybe even more, I finally understood how to set up the PIT and add a handler in the IVT, thus, the framerate is now fully faithful to the original!
50+
If it is still too slow, that means your CPU might not be able to handle the video at the original framerate. In that case, you can change the `FPS` variable in the `Makefile` to a lower value.
5651

5752
## FAQ
5853

@@ -61,7 +56,8 @@ There are two main reasons for this project:
6156

6257
Firstly, I wanted to learn more about low-level programming, more specifically Assembly. I already made [an operating system](https://github.com/bemxio/bemxos), however, the Assembly side has attracted me the most. I wanted to challenge myself into using it for something bigger, in order to properly learn registers, interrupts and things like that. Perhaps, in the future, I will step into NES development!
6358

64-
~~Secondly, no one has done this before.~~ Actually, I was wrong. [@redstone_flash5774](https://www.youtube.com/channel/UCxL3ay5lRA4KvCX56sRIUeA) made their version and uploaded it to YouTube [here](https://www.youtube.com/watch?v=DsJH3SNYqvM). I didn't notice it at all in those 6 months, just found it out when I was uploading my video on YouTube. Still, our approaches to do it are different, and they have not uploaded the source code, so I guess I can still be proud of it!
59+
~~Secondly, no one has done this before.~~
60+
Actually, I was wrong. [@redstone_flash5774](https://www.youtube.com/channel/UCxL3ay5lRA4KvCX56sRIUeA) made their version and uploaded it to YouTube [here](https://www.youtube.com/watch?v=DsJH3SNYqvM). I didn't notice it at all in those 6 months, just found it out when I was uploading my video on YouTube. Still, our approaches to do it are different, and they have not uploaded the source code, so I guess I can still be proud of it!
6561

6662
### How does it work?
6763
The `bootloader.bin` file is split into two parts - the first one is the bootloader itself, with all of the code, and the second one is the video data.

src/pit.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
IVT_IRQ0_OFFSET equ 0x0020 ; the offset of the first IRQ in the IVT
2-
PIT_RELOAD_VALUE equ 0x9b5c ; the reload value for the PIT (0x9b5c, 39722, results in 30 hz/FPS)
2+
;PIT_RELOAD_VALUE equ 0x9b5c ; the reload value for the PIT (0x9b5c, 39772, results in 30 hz/FPS)
33

44
setup_pit:
55
pusha ; save the registers
66

77
mov al, 0x34 ; set the command byte (channel 0, lobyte/hibyte, rate generator)
88
out 0x43, al ; send the command byte to the PIT
99

10-
mov ax, PIT_RELOAD_VALUE ; set the reload value (0x9b5c, 39722, results in 30 hz/FPS)
10+
mov ax, PIT_RELOAD_VALUE ; set the reload value
1111

1212
out 0x40, al ; send the low byte to the PIT
1313

0 commit comments

Comments
 (0)