Commit 386b1423 authored by Uriel Chami's avatar Uriel Chami
Browse files

Casi todo el tp done

parent 58c2a766
......@@ -16,46 +16,54 @@
#define CODE_n 0x31
#define CODE_m 0x32
char* mensajesJugadorA[3];
char* mensajesJugadorB[3];
coordenadaPelota coordsPelotasPorSlot[6];
uint32_t alturaJugadorA;
uint32_t alturaJugadorB;
e_action_t movimientosPendientesPorSlot[6];
void game_init() {
alturaJugadorA = 20;
alturaJugadorB = 20;
for(int i = 0; i <= 5; i++){
movimientosPendientesPorSlot[i] = Center;
}
for(int i=0; i < 3; i++){
mensajesJugadorA[i][0] = '\0';
mensajesJugadorB[i][0] = '\0';
}
pelotasDisponiblesA = 15;
pelotasDisponiblesB = 15;
//crearPelota(1, 0);
//crearPelota(1, 0);
}
void iniciarTarea(uint32_t slotLibre, uint32_t tipoDePelota){
//pongo como viva la pelota
pelotas_vivas[slotLibre] = 1;
userLevelTasksCodeAndStacks[slotLibre] = mmu_initTaskDir(tipoDePelota);
//lleno la tss de la tarea
initUserTask(slotLibre, 0, 0);
}
void crearPelota(uint32_t esJugadorA, uint32_t tipoDePelota){
uint32_t slotLibre = dameSlotLibre(esJugadorA);
if(slotLibre < 6){
if( esJugadorA ){
if( esJugadorA && pelotasDisponiblesA > 0){
//la pelota es del jugador A
coordsPelotasPorSlot[slotLibre].x = 1; // arranca justo adelante del jugador
pelotasDisponiblesA--;
coordsPelotasPorSlot[slotLibre].x = 0; // arranca justo adelante del jugador
coordsPelotasPorSlot[slotLibre].y = alturaJugadorA; // arranca en el centro de la posicion del jugador
coordsPelotasPorSlot[slotLibre].direccionX = 1; // 1 = derecha
coordsPelotasPorSlot[slotLibre].direccionY = 0; // 0 = no invertida
} else {
iniciarTarea(slotLibre, tipoDePelota);
} else if(!esJugadorA && pelotasDisponiblesB > 0) {
//pelota del jugador B
coordsPelotasPorSlot[slotLibre].x = 78;
pelotasDisponiblesB--;
coordsPelotasPorSlot[slotLibre].x = 79;
coordsPelotasPorSlot[slotLibre].y = alturaJugadorB;
coordsPelotasPorSlot[slotLibre].direccionX = 0; // 0 = izquierda
coordsPelotasPorSlot[slotLibre].direccionY = 0; // 0 = no invertida
iniciarTarea(slotLibre, tipoDePelota);
}
//pongo como viva la pelota
print_dec(slotLibre, 1, 20,20,0xC);
pelotas_vivas[slotLibre] = 1;
userLevelTasksCodeAndStacks[slotLibre] = mmu_initTaskDir(tipoDePelota);
//lleno la tss de la tarea
initUserTask(slotLibre, 0, 0);
}
}
......@@ -75,6 +83,7 @@ e_action_t invertir(e_action_t accion, uint32_t invierte) {
}
void atender_teclado(uint8_t tecla_presionada){
//TODO: Que onda con el enunciado que nos dice "limitar una accion cada 30 ciclos"????
switch(tecla_presionada){
case CODE_w:
//mover hacia arriba jugador A
......@@ -118,6 +127,24 @@ void atender_teclado(uint8_t tecla_presionada){
break;
}
}
void copiarString(uint32_t index, char* src, uint32_t esJugadorA){
// TODO: Los mensajes claramente andan mal. Creemos que se debe a
// que la copia no es deep, es decir,
// no estamos copiando realmente si no pasando punteritos de aca pa alla
int i;
for(i=0; i < 20 && src[i] != 0; i++){
if(esJugadorA){
mensajesJugadorA[index][i] = src[i];
} else {
mensajesJugadorB[index][i] = src[i];
}
}
if(esJugadorA){
mensajesJugadorA[index][i] = '\0';
} else {
mensajesJugadorB[index][i] = '\0';
}
}
void moverJugador(uint32_t esJugadorA, e_action_t movimientoAEjecutar){
uint32_t altura;
......@@ -136,24 +163,11 @@ void moverJugador(uint32_t esJugadorA, e_action_t movimientoAEjecutar){
altura++;
}
}
if(esJugadorA){
//cambiar variables de altura
alturaJugadorA = altura;
//dibujar jugador
//limpiamos borde izquierdo
screen_drawBox(0, 0, 40, 1, 0x32, C_BG_GREEN + C_FG_GREEN);
//ahora dibujo al jugador A
screen_drawBox(alturaJugadorA - 3, 0, 7, 1, 0x32, 0xCC);
} else {
alturaJugadorB = altura;
//dibujar jugador
//limpiamos borde derecho
screen_drawBox(0, 79, 40, 1, 0x32, C_BG_GREEN + C_FG_GREEN);
//ahora dibujo al jugador B
screen_drawBox(alturaJugadorB - 3, 79, 7, 1, 0x32, 0x99);
}
}
......@@ -178,7 +192,6 @@ coordenadaPelota moverEnVertical(coordenadaPelota coordActual, e_action_t movimi
}
uint32_t laAtaja(uint32_t alturaPelota, uint32_t alturaJugador){
//TODO: Mirar aca si el atajado anda mal
if(alturaJugador - 3 <= alturaPelota && alturaPelota <= alturaJugador + 3){
return 1;
} else {
......@@ -186,11 +199,19 @@ uint32_t laAtaja(uint32_t alturaPelota, uint32_t alturaJugador){
}
}
coordenadaPelota moverEnHorizontal(coordenadaPelota coordActual) {
void matarTarea(uint32_t slot){
pelotas_vivas[slot] = 0;
handlers_activos[slot] = 0;
movimientosPendientesPorSlot[slot] = Center;
}
coordenadaPelota moverEnHorizontal(coordenadaPelota coordActual, uint32_t slot) {
if(coordActual.direccionX) {
//derecha
if(coordActual.x == 79){
//TODO: matar tarea y borrarla de la pantalla pq esta en la columna 79
//mato la tarea
matarTarea(slot);
puntajeA += 100;
} else if( coordActual.x == 78 && laAtaja(coordActual.y, alturaJugadorB) ){
coordActual.direccionX = !coordActual.direccionX;
} else {
......@@ -199,7 +220,10 @@ coordenadaPelota moverEnHorizontal(coordenadaPelota coordActual) {
} else {
//izquierda
if(coordActual.x == 0){
//TODO: matar tarea y borrarla de la pantalla pq esta en la columna 0
//mato la tarea
matarTarea(slot);
puntajeB += 100;
} else if( coordActual.x == 1 && laAtaja(coordActual.y, alturaJugadorA) ){
coordActual.direccionX = !coordActual.direccionX;
} else {
......@@ -210,55 +234,111 @@ coordenadaPelota moverEnHorizontal(coordenadaPelota coordActual) {
}
void dibujarPantalla(){
//screen_drawBox(0, 1, 40, 78, 0x32, 0x88); // limpio el tablero (en particular, las pelotas)
//TODO: MODO DEBUG! (atender tecla Y, poner cartelito, cortar las tareas, reestablecer)
//TODO: Matar tareas cuando se tomaron mas de un ciclo de clock en el handler
//TODO: Matar tareas cuando tienen una excepcion fuera del modo debug (es llamar a matarTare(quantum))
// limpio el tablero (en particular, las pelotas)
screen_drawBox(0, 1, 40, 78, 0x32, 0x88);
for(uint32_t i = 0; i <= 5; i++){
coordenadaPelota coordActual = coordsPelotasPorSlot[i];
e_action_t movimientoAEjecutar = invertir(movimientosPendientesPorSlot[i], coordActual.direccionY);
if(pelotas_vivas[i] != 0) {
coordenadaPelota coordActual = coordsPelotasPorSlot[i];
e_action_t movimientoAEjecutar = invertir(movimientosPendientesPorSlot[i], coordActual.direccionY);
//aca calculamos como va a ser el movimiento en vertical en el siguiente tick del juego
coordActual = moverEnVertical(coordActual, movimientoAEjecutar);
// same para horizontal
coordActual = moverEnHorizontal(coordActual);
//aca calculamos como va a ser el movimiento en vertical en el siguiente tick del juego
coordActual = moverEnVertical(coordActual, movimientoAEjecutar);
// same para horizontal
coordActual = moverEnHorizontal(coordActual, i);
// aca dibujamos en pantalla ese resultado.
if(pelotas_vivas[i] != 0) {
coordsPelotasPorSlot[i] = coordActual;
uint8_t atributos;
if(0 <= i && i <= 2) {
atributos = C_BG_DARK_GREY + C_FG_LIGHT_RED; // la pelota era del jugador A. So, la pelota es del color de A
} else {
atributos = C_BG_DARK_GREY + C_FG_LIGHT_BLUE;
}
// aca dibujamos en pantalla ese resultado.
print("*", coordActual.x, coordActual.y, atributos);
}
}
// imprimo jugador A
// limpio borde izquierdo
screen_drawBox(0, 0, 40, 1, 0x32, C_BG_GREEN + C_FG_GREEN);
// ahora dibujo al jugador A
screen_drawBox(alturaJugadorA - 3, 0, 7, 1, 0x32, 0xCC);
// imprimo jugador B
// limpio borde derecho
screen_drawBox(0, 79, 40, 1, 0x32, C_BG_GREEN + C_FG_GREEN);
// ahora dibujo al jugador B
screen_drawBox(alturaJugadorB - 3, 79, 7, 1, 0x32, 0x99);
//imprimo mensajes
screen_drawBox(45, 1, 4, 38, 0x32, 0xCC);
screen_drawBox(45, 41, 4, 38, 0x32, 0x99);
for(int i=0; i < 3; i++){
print(mensajesJugadorA[i], 4, (45 + i), 0xF0);
print(mensajesJugadorB[i], 44, (45 + i), 0xF0);
}
//imprimo "puntos"
print("Puntos:", 2, 42, 0xF0);
print_dec(puntajeA, 4, 10, 42, 0xF0);
print("Puntos:", 42, 42, 0xF0);
print_dec(puntajeB, 4, 50, 42, 0xF0);
//imprimo "pelotas"
print("Pelotas:", 2, 43, 0xF0);
print_dec(pelotasDisponiblesA, 2, 11, 43, 0xF0);
print("Pelotas:", 42, 43, 0xF0);
print_dec(pelotasDisponiblesB, 2, 51, 43, 0xF0);
//imprimo slots con pelotas activas (o no)
for(int i= 0; i < 3; i++){
//i esimo slot de pelotas de A
char* taVivo = pelotas_vivas[i] ? "O" : "X";
print(taVivo, 32 + 2*i, 42, 0xF0);
//i esimo slot de pelotas de B
taVivo = pelotas_vivas[i+3] ? "O" : "X";
print(taVivo, 72 + 2*i, 42, 0xF0);
}
}
void actualizarMovimientoPendiente(e_action_t action){
movimientosPendientesPorSlot[quantum] = action;
}
coordenadaPelota* dameCoordenadas(){
//aca quantum = slot.
return &(coordsPelotasPorSlot[quantum]);
}
void write_message(char* message){
uint32_t esJugadorA = 0;
if(quantum < 3){
esJugadorA = 1;
} else {
esJugadorA = 0;
}
void write_message(uint16_t player, char* message){
//TODO: chequear que message.length <= 20. (wont fix)
// player 0 = A
// player 1 = B
if(player == 0){
if(esJugadorA){
// "push" --> mensajesJugadorA.push(message);
mensajesJugadorA[2] = mensajesJugadorA[1];
mensajesJugadorA[1] = mensajesJugadorA[0];
mensajesJugadorA[0] = message;
copiarString(2, mensajesJugadorA[1],1);
copiarString(1, mensajesJugadorA[0],1);
copiarString(0, message,1);
} else {
mensajesJugadorB[2] = mensajesJugadorB[1];
mensajesJugadorB[1] = mensajesJugadorB[0];
mensajesJugadorB[0] = message;
copiarString(2, mensajesJugadorB[1],0);
copiarString(1, mensajesJugadorB[0],0);
copiarString(0, message,0);
}
}
coordenadaPelota where_is(uint32_t type){
return coordsPelotasPorSlot[type];
}
......@@ -12,24 +12,12 @@
#include "screen.h"
#include "mmu.h"
#include "sched.h"
#include "gameStructs.h"
typedef void (*f_handler_t)();
typedef struct str_coordenadaPelota {
uint32_t x;
uint32_t y;
uint32_t direccionX; //0 = izquierda, 1 = derecha.
uint32_t direccionY; //0 = no invertido, 1 = invertido
} coordenadaPelota;
typedef enum e_action {
Up = 1,
Center = 2,
Down = 3,
} e_action_t;
coordenadaPelota* dameCoordenadas();
void matarTarea(uint32_t murioDelLadoDerecho, uint32_t slot);
void crearPelota(uint32_t esJugadorA, uint32_t tipoDePelota);
void atender_teclado(uint8_t tecla_presionada);
void moverJugador(uint32_t esJugadorA, e_action_t movimientoAEjecutar);
......
#ifndef __GAME_STRUCTS_H__
#define __GAME_STRUCTS_H__
//mrs quantum que rige la vida
int32_t quantum;
// handlers_activos[i] == 0 ===> El handler de la tarea-i esta inactivo.
// handlers_activos[i] != 0 ===> El handler de la tarea-i esta activo y es handlers_activos[i].
// handlers_activos[0]: Handler de la pelota del Jugador A Slot 1
// handlers_activos[1]: Handler de la pelota del Jugador A Slot 2
// handlers_activos[2]: Handler de la pelota del Jugador A Slot 3
// handlers_activos[3]: Handler de la pelota del Jugador B Slot 1
// handlers_activos[4]: Handler de la pelota del Jugador B Slot 2
// handlers_activos[5]: Handler de la pelota del Jugador B Slot 3
uint32_t handlers_activos[6];
// pelotas_vivas[i] == 1 ===> La pelota-i esta viva.
// pelotas_vivas[0]: pelota del Jugador A Slot 1
// pelotas_vivas[1]: pelota del Jugador A Slot 2
// pelotas_vivas[2]: pelota del Jugador A Slot 3
// pelotas_vivas[3]: pelota del Jugador B Slot 1
// pelotas_vivas[4]: pelota del Jugador B Slot 2
// pelotas_vivas[5]: pelota del Jugador B Slot 3
uint32_t pelotas_vivas[6];
typedef struct str_coordenadaPelota {
uint32_t x;
uint32_t y;
uint32_t direccionX; //0 = izquierda, 1 = derecha.
uint32_t direccionY; //0 = no invertido, 1 = invertido
} coordenadaPelota;
typedef enum e_action {
Up = 1,
Center = 2,
Down = 3,
} e_action_t;
char* mensajesJugadorA[3];
char* mensajesJugadorB[3];
coordenadaPelota coordsPelotasPorSlot[6];
uint32_t alturaJugadorA;
uint32_t alturaJugadorB;
e_action_t movimientosPendientesPorSlot[6];
uint32_t kernelLevelTasksStacks[6]; // array de esp0's
uint32_t userLevelTasksCodeAndStacks[6]; // array de CR3's
uint32_t pelotasDisponiblesA;
uint32_t pelotasDisponiblesB;
uint32_t puntajeA;
uint32_t puntajeB;
#endif /* !__GAME_STRUCTS_H__ */
\ No newline at end of file
......@@ -21,6 +21,8 @@ extern saltarDeHandlerATarea
extern print_exception
extern dibujarPantalla
extern atender_teclado
extern dameCoordenadas
extern write_message
;;
;; Definición de MACROS
......@@ -135,13 +137,19 @@ _isr33:
;; Rutinas de atención de las SYSCALLS
;; -------------------------------------------------------------------------- ;;
whereX: DD 0
whereY: DD 0
global _isr47
_isr47:
pushad ; preservo estado del sistema
cmp eax, 0x80000003
je .setHandler
jmp .sigo1
.setHandler:
call setHandler
jmp .popRegisters
.sigo1:
cmp eax, 0x80000001
......@@ -149,22 +157,37 @@ _isr47:
jmp .sigo2
.talk:
call talk
jmp .popRegisters
.sigo2:
cmp eax, 0x80000002
je .where
jmp .sigo3
.where:
call where
jmp .popWhere
.sigo3:
cmp eax, 0x8000FFFF
je .informAction
jmp .sigo4
jmp .popRegisters
.informAction:
call informAction
jmp .popRegisters
.popRegisters:
popad ; recupero estado previo a la interrupcion
jmp .fin
.sigo4:
.popWhere:
mov [whereX], ebx
mov [whereY], ecx
popad
mov ebx, [whereX]
mov ecx, [whereY]
jmp .fin
.fin:
iret
;; Funciones Auxiliares
......@@ -187,27 +210,24 @@ nextClock:
;debe preservar eax
setHandler:
pushad
push ebx
call setHandlerValue
add esp, 4
popad
ret
talk:
pushad
;COMPLETAR
popad
push ebx
call write_message
add esp, 4
ret
where:
pushad
;COMPLETAR
popad
call dameCoordenadas
mov ebx, [eax + 0] ;coordPelota.x
mov ecx, [eax + 4] ;coordPelota.y
ret
informAction:
pushad
;call a game.c
push ebx
......@@ -217,7 +237,6 @@ informAction:
;call a sched.c
call saltarDeHandlerATarea
popad
ret
......@@ -61,6 +61,8 @@ puntos_msg db 'Puntos:'
puntos_len equ $ - puntos_msg
pelotas_msg db 'Pelotas:'
pelotas_len equ $ - pelotas_msg
mensajes_msg db 'Mensajes:'
mensajes_len equ $ - mensajes_msg
;;
;; Seccion de código.
......@@ -184,18 +186,6 @@ start:
push 17 ; fInit
call screen_drawBox ; screen_drawBox(17, 0, 7, 1, 0x32, 0xCC)
; imprimo Puntos, Pelotas.
print_text_pm puntos_msg, puntos_len, 0xF0, 42, 2 ; puntero al mensaje (puntos_msg), longitud del mensaje (puntos_len), color (0xF0, es decir, C_BG_WHITE y C_FG_BLACK), fila y columna (0,0).
print_text_pm pelotas_msg, pelotas_len, 0xF0, 43, 2
print_text_pm puntos_msg, puntos_len, 0xF0, 42, 42
print_text_pm pelotas_msg, pelotas_len, 0xF0, 43, 42
; el resto deberia ser hecho/actualizado por alguna tarea.
; de hecho, imprimir los puntos y las pelotas no es parte del ejercicio 1. Lo dejo porque despues va a servir como molde, pero va a volar
; ---------------------------- Fin Clase 1 --------------------------------
......@@ -326,7 +316,7 @@ selector: DW 0
saltarATarea: ; [esp] = selectorDeSegmento
push eax
xchg bx, bx
;xchg bx, bx
mov ax, word [esp]
mov [selector], ax
jmp far [offset] ; con esto saltamos a la entrada selectorDeSegmento de la GDT.
......
......@@ -67,8 +67,7 @@ void next_quantum(){
}
void setHandlerValue(uint32_t punteritoAlCodigoDelHandler){
//como el quantum lo avanzamos justo al inicializar la tarea,
//en esta instancia quantum - 1 sera el tipo de tarea que
//en esta instancia quantum sera el slot de tarea que
//se esta ejecutando en este momento
handlers_activos[quantum] = punteritoAlCodigoDelHandler;
}
......
......@@ -11,8 +11,7 @@
#include "stdint.h"
#include "screen.h"
#include "tss.h"
int32_t quantum;
#include "gameStructs.h"
void sched_init();
......@@ -25,25 +24,4 @@ uint32_t dameSlotLibre(uint32_t esJugadorA);
// handlers_activos[i] == 0 ===> El handler de la tarea-i esta inactivo.
// handlers_activos[i] != 0 ===> El handler de la tarea-i esta activo y es handlers_activos[i].
// handlers_activos[0]: Handler de la pelota del Jugador A Slot 1
// handlers_activos[1]: Handler de la pelota del Jugador A Slot 2
// handlers_activos[2]: Handler de la pelota del Jugador A Slot 3
// handlers_activos[3]: Handler de la pelota del Jugador B Slot 1
// handlers_activos[4]: Handler de la pelota del Jugador B Slot 2
// handlers_activos[5]: Handler de la pelota del Jugador B Slot 3
uint32_t handlers_activos[6];
// pelotas_vivas[i] == 1 ===> La pelota-i esta viva.
// pelotas_vivas[0]: pelota del Jugador A Slot 1
// pelotas_vivas[1]: pelota del Jugador A Slot 2
// pelotas_vivas[2]: pelota del Jugador A Slot 3
// pelotas_vivas[3]: pelota del Jugador B Slot 1
// pelotas_vivas[4]: pelota del Jugador B Slot 2
// pelotas_vivas[5]: pelota del Jugador B Slot 3
uint32_t pelotas_vivas[6];
#endif /* !__SCHED_H__ */
......@@ -9,7 +9,7 @@
void handler(void);
void task() {
char* message = "Tarea A1";
char* message = "Soy la tareita A1";
syscall_talk(message);
syscall_setHandler(handler);
......
......@@ -7,8 +7,6 @@
#include "tss.h"
//SI LLEGA A MORIR TODO, COMPLETAR SS FS Y EBP!!
#define tasksAndHandlers_ptl 0
#define tasksAndHandlers_unused0 0
......
......@@ -13,9 +13,8 @@
#include "i386.h"
#include "gdt.h"
#include "mmu.h"
#include "gameStructs.h"
uint32_t kernelLevelTasksStacks[6]; // array de esp0's
uint32_t userLevelTasksCodeAndStacks[6]; // array de CR3's
typedef struct str_tss {
uint16_t ptl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment